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
Provenance
- Commit
4b63cd8- Tree
87c8c1d- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
a98d482
1 file changed+24 added−21 removed
modified:docs/templates.rst+24 added-21 removed
1128 unmodified lines1129 1130 Include1131 ~~~~~~~1132 1133-The `include` tag is useful to include a template and return the1134-rendered contents of that file into the current namespace::1133+The ``include`` tag renders another template and outputs the result into1134+the current template.1135 1136+.. code-block:: jinja1137+1138 {% include 'header.html' %}1137- Body1139+ Body goes here.1140 {% include 'footer.html' %}1141 1140-Included templates have access to the variables of the active context by1141-default. For more details about context behavior of imports and includes,1142-see :ref:`import-visibility`.1142+The included template has access to context of the current template by1143+default. Use ``without context`` to use a separate context instead.1144+``with context`` is also valid, but is the default behavior. See1145+:ref:`import-visibility`.1146 1144-From Jinja 2.2 onwards, you can mark an include with ``ignore missing``; in1145-which case Jinja will ignore the statement if the template to be included1146-does not exist. When combined with ``with`` or ``without context``, it must1147-be placed *before* the context visibility statement. Here are some valid1148-examples::1147+The included template can ``extend`` another template and override1148+blocks in that template. However, the current template cannot override1149+any blocks that the included template outputs.1150 1151+Use ``ignore missing`` to ignore the statement if the template does not1152+exist. It must be placed *before* a context visibility statement.1153+1154+.. code-block:: jinja1155+1156+ {% 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 %}1160 1154-.. versionadded:: 2.21161+If a list of templates is given, each will be tried in order until one1162+is not missing. This can be used with ``ignore missing`` to ignore if1163+none of the templates exist.1164 1156-You can also provide a list of templates that are checked for existence1157-before inclusion. The first template that exists will be included. If1158-`ignore missing` is given, it will fall back to rendering nothing if1159-none of the templates exist, otherwise it will raise an exception.1165+.. code-block:: jinja1166 1161-Example::1162-1167 {% include ['page_detailed.html', 'page.html'] %}1168 {% include ['special_sidebar.html', 'sidebar.html'] ignore missing %}1169 1166-.. versionchanged:: 2.41167- If a template object was passed to the template context, you can1168- include that object using `include`.1170+A variable, with either a template name or template object, can also be1171+passed to the statment.1172 1173 .. _import:1174 1175 Import774 unmodified lines