mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-21 07:37:43 +00:00
added a way to ignore a missing template when using the "include" tag
This commit is contained in:
@@ -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
|
||||
~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user