Promote the include() function instead of the "include" tag

This commit is contained in:
Javier Eguiluz
2016-04-17 19:40:15 +02:00
parent f0a4fa6784
commit ea090df8d9
+9 -10
View File
@@ -293,25 +293,24 @@ designers or yourself:
Including other Templates Including other Templates
------------------------- -------------------------
The :doc:`include<tags/include>` tag is useful to include a template and The :doc:`include<functions/include>` function is useful to include a template
return the rendered content of that template into the current one: and return the rendered content of that template into the current one:
.. code-block:: jinja .. code-block:: jinja
{% include 'sidebar.html' %} {{ include('sidebar.html') }}
Per default included templates are passed the current context. By default, included templates have access to the same context as the template
which includes them. This means that any variable defined in the main template
The context that is passed to the included template includes variables defined will be available in the included template too:
in the template:
.. code-block:: jinja .. code-block:: jinja
{% for box in boxes %} {% for box in boxes %}
{% include "render_box.html" %} {{ include('render_box.html') }}
{% endfor %} {% endfor %}
The included template ``render_box.html`` is able to access ``box``. The included template ``render_box.html`` is able to access ``box`` variable.
The filename of the template depends on the template loader. For instance, the The filename of the template depends on the template loader. For instance, the
``Twig_Loader_Filesystem`` allows you to access other templates by giving the ``Twig_Loader_Filesystem`` allows you to access other templates by giving the
@@ -319,7 +318,7 @@ filename. You can access templates in subdirectories with a slash:
.. code-block:: jinja .. code-block:: jinja
{% include "sections/articles/sidebar.html" %} {{ include('sections/articles/sidebar.html') }}
This behavior depends on the application embedding Twig. This behavior depends on the application embedding Twig.