From: Kevin Date: Tue, 12 May 2020 01:10:26 +0000 (-0400) Subject: Add support for the extends block X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=83665a17069fa165c83a0578baf8ec984fbe898c;p=thirdparty%2Fjinja.git Add support for the extends block --- diff --git a/new_parser.py b/new_parser.py index ea79e95d..c55d91d9 100644 --- a/new_parser.py +++ b/new_parser.py @@ -67,6 +67,9 @@ def parse(ast): def parse_block(ast): block_name = ast['block']['name'] + if block_name == 'extends': + return parse_block_extends(ast) + if block_name == 'from': return parse_block_from(ast) @@ -126,6 +129,11 @@ def parse_block_block(ast): lineno=lineno_from_parseinfo(ast['parseinfo']) ) +def parse_block_extends(ast): + return nodes.Extends( + parse_conditional_expression(ast['block']['parameters'][0]['value']) + ) + def parse_block_for(ast): target = None iter = None diff --git a/test_template.jinja b/test_template.jinja index afad4325..ad3035c9 100644 --- a/test_template.jinja +++ b/test_template.jinja @@ -64,4 +64,5 @@ across lines #} 'id': 'list-%d'|format(variable)}|xmlattr }}> ... -{{ "[{}]".format(page.title) if page.title }} \ No newline at end of file +{{ "[{}]".format(page.title) if page.title }} +{% extends layout_template if layout_template is defined else 'master.html' %} \ No newline at end of file