Skip to content
Myr

rewrite include statement section

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent a98d482 · Browse files · 1 file+24 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−21 removed

  • other:+24 added−21 removed

1 file+24 added−21 removed

modified:docs/templates.rst+24 added-21 removed
1128 unmodified lines
11291130Include1131~~~~~~~11321133The `include` tag is useful to include a template and return the1134rendered contents of that file into the current namespace::1133The ``include`` tag renders another template and outputs the result into1134the current template.11351136.. code-block:: jinja11371138 {% include 'header.html' %}1137 Body1139 Body goes here.1140 {% include 'footer.html' %}11411140Included templates have access to the variables of the active context by1141default. For more details about context behavior of imports and includes,1142see :ref:`import-visibility`.1142The included template has access to context of the current template by1143default. Use ``without context`` to use a separate context instead.1144``with context`` is also valid, but is the default behavior. See1145:ref:`import-visibility`.11461144From Jinja 2.2 onwards, you can mark an include with ``ignore missing``; in1145which case Jinja will ignore the statement if the template to be included1146does not exist. When combined with ``with`` or ``without context``, it must1147be placed *before* the context visibility statement. Here are some valid1148examples::1147The included template can ``extend`` another template and override1148blocks in that template. However, the current template cannot override1149any blocks that the included template outputs.11501151Use ``ignore missing`` to ignore the statement if the template does not1152exist. It must be placed *before* a context visibility statement.11531154.. code-block:: jinja11551156 {% include "sidebar.html" without context %}1157 {% include "sidebar.html" ignore missing %}1158 {% include "sidebar.html" ignore missing with context %}1159 {% include "sidebar.html" ignore missing without context %}11601154.. versionadded:: 2.21161If a list of templates is given, each will be tried in order until one1162is not missing. This can be used with ``ignore missing`` to ignore if1163none of the templates exist.11641156You can also provide a list of templates that are checked for existence1157before inclusion. The first template that exists will be included. If1158`ignore missing` is given, it will fall back to rendering nothing if1159none of the templates exist, otherwise it will raise an exception.1165.. code-block:: jinja11661161Example::11621167 {% include ['page_detailed.html', 'page.html'] %}1168 {% include ['special_sidebar.html', 'sidebar.html'] ignore missing %}11691166.. versionchanged:: 2.41167 If a template object was passed to the template context, you can1168 include that object using `include`.1170A variable, with either a template name or template object, can also be1171passed to the statment.11721173.. _import:11741175Import
774 unmodified lines