From 9cf1c578d4477880449fbca52ba6dbb0ed1ac10f Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 12 May 2020 16:56:53 -0400 Subject: [PATCH] Add support for `{% include ignore missing %}` --- new_parser.py | 6 ++++++ test_template.jinja | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/new_parser.py b/new_parser.py index 0ed8ec7f..b3dd8ac9 100644 --- a/new_parser.py +++ b/new_parser.py @@ -254,6 +254,12 @@ def parse_block_include(ast): else: del block_parameters[-2:] + if len(block_parameters) == 3: + ignore_missing = True + + if block_parameters[1]['value']['variable'] != 'ignore' and block_parameters[2]['value']['variable'] != 'missing': + raise + return nodes.Include( template, with_context, diff --git a/test_template.jinja b/test_template.jinja index 603e1920..399f898f 100644 --- a/test_template.jinja +++ b/test_template.jinja @@ -73,4 +73,8 @@ across lines #} {{ foo not in bar }} {% from 'forms.html' import input with context %} {% include 'header.html' without context %} -{% import 'forms.html' as forms %} \ No newline at end of file +{% import 'forms.html' as forms %} +{% include ['special_sidebar.html', 'sidebar.html'] ignore missing %} +{% include "sidebar.html" ignore missing %} +{% include "sidebar.html" ignore missing with context %} +{% include "sidebar.html" ignore missing without context %} \ No newline at end of file -- 2.47.3