added a way to ignore a missing template when using the "include" tag

This commit is contained in:
Fabien Potencier
2011-08-27 13:54:33 +02:00
parent 35a8a0d155
commit c56dd32f57
6 changed files with 74 additions and 9 deletions
+18
View File
@@ -877,14 +877,32 @@ directly::
$twig->loadTemplate('template.twig')->display(array('template' => $template));
.. versionadded:: 1.2
The ``ignore missing`` feature has been added in Twig 1.2.
You can mark an include with ``ignore missing`` in which case Twig will ignore
the statement if the template to be ignored does not exist. It has to be
placed just after the template name. Here some valid examples::
.. code-block:: jinja
{% include "sidebar.html" ignore missing %}
{% include "sidebar.html" ignore missing with {'foo': 'bar} %}
{% include "sidebar.html" ignore missing only %}
.. versionadded:: 1.2
The possibility to pass an array of templates has been added in Twig 1.2.
You can also provide a list of templates that are checked for existence before
inclusion. The first template that exists will be included::
.. code-block:: jinja
{% include ['page_detailed.html', 'page.html'] %}
If ``ignore missing`` is given, it will fall back to rendering nothing if none
of the templates exist, otherwise it will throw an exception.
Import
~~~~~~