]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add support for parsing `{% include %}` tags
authorKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 02:48:12 +0000 (22:48 -0400)
committerKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 02:48:12 +0000 (22:48 -0400)
This does not yet support the `ignore_missing` flag that can be
passed as a parameter to an `{% include %}` tag

new_parser.py
test_template.jinja

index 88cd4a62fea866d6c26c67102e89f7725c916726..f786b9f7fd7c26cb3d79af57197b9cdba80769bd 100644 (file)
@@ -73,6 +73,9 @@ def parse_block(ast):
     if block_name == 'from':\r
         return parse_block_from(ast)\r
 \r
+    if block_name == 'include':\r
+        return parse_block_include(ast)\r
+\r
     if block_name == 'set':\r
         return parse_block_set(ast)\r
 \r
@@ -220,6 +223,25 @@ def parse_block_if(ast):
         lineno=lineno_from_parseinfo(ast['parseinfo'])\r
     )\r
 \r
+def parse_block_include(ast):\r
+    block_parameters = ast['block']['parameters']\r
+\r
+    template = parse_conditional_expression(block_parameters[0]['value'])\r
+    with_context = _parse_import_context(block_parameters)\r
+    ignore_missing = False\r
+\r
+    if with_context is None:\r
+        with_context = False\r
+    else:\r
+        del block_parameters[-2:]\r
+\r
+    return nodes.Include(\r
+        template,\r
+        with_context,\r
+        ignore_missing,\r
+        lineno=lineno_from_parseinfo(ast['parseinfo'])\r
+    )\r
+\r
 def parse_block_macro(ast):\r
     definition = parse_variable(ast['start']['parameters'][0]['value'])\r
     name = definition.node.name\r
index f1a76e3a49ea481035228e5671735eb21abe1a60..9651b8e07a7f82f22124d72430d4c27c54cf51e8 100644 (file)
@@ -71,4 +71,5 @@ across lines #}
 {{ foo is not bar }}\r
 {{ not (foo and bar) }}\r
 {{ foo not in bar }}\r
-{% from 'forms.html' import input with context %}
\ No newline at end of file
+{% from 'forms.html' import input with context %}\r
+{% include 'header.html' without context %}
\ No newline at end of file