Skip to content

Commit

Permalink
update other .rst templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepperoni1337 committed Dec 18, 2024
1 parent e2dd832 commit 0365afe
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 67 deletions.
20 changes: 10 additions & 10 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Rendering Templates
To load a template from a Twig environment, call the ``load()`` method which
returns a ``\Twig\TemplateWrapper`` instance::

$template = $twig->load('index.html');
$template = $twig->load('index.html.twig');

To render the template with some variables, call the ``render()`` method::

Expand All @@ -58,7 +58,7 @@ To render the template with some variables, call the ``render()`` method::

You can also load and render the template in one fell swoop::

echo $twig->render('index.html', ['the' => 'variables', 'go' => 'here']);
echo $twig->render('index.html.twig', ['the' => 'variables', 'go' => 'here']);

If a template defines blocks, they can be rendered individually via the
``renderBlock()`` call::
Expand Down Expand Up @@ -177,7 +177,7 @@ methods act on the "main" namespace)::
Namespaced templates can be accessed via the special
``@namespace_name/template_path`` notation::

$twig->render('@admin/index.html', []);
$twig->render('@admin/index.html.twig', []);

``\Twig\Loader\FilesystemLoader`` supports absolute and relative paths. Using relative
paths is preferred as it makes the cache keys independent of the project root
Expand All @@ -198,11 +198,11 @@ the directory might be different from the one used on production servers)::
array of strings bound to template names::

$loader = new \Twig\Loader\ArrayLoader([
'index.html' => 'Hello {{ name }}!',
'index.html.twig' => 'Hello {{ name }}!',
]);
$twig = new \Twig\Environment($loader);

echo $twig->render('index.html', ['name' => 'Fabien']);
echo $twig->render('index.html.twig', ['name' => 'Fabien']);

This loader is very useful for unit testing. It can also be used for small
projects where storing all templates in a single PHP file might make sense.
Expand All @@ -221,20 +221,20 @@ projects where storing all templates in a single PHP file might make sense.
``\Twig\Loader\ChainLoader`` delegates the loading of templates to other loaders::

$loader1 = new \Twig\Loader\ArrayLoader([
'base.html' => '{% block content %}{% endblock %}',
'base.html.twig' => '{% block content %}{% endblock %}',
]);
$loader2 = new \Twig\Loader\ArrayLoader([
'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}',
'base.html' => 'Will never be loaded',
'index.html.twig' => '{% extends "base.html.twig" %}{% block content %}Hello {{ name }}{% endblock %}',
'base.html.twig' => 'Will never be loaded',
]);

$loader = new \Twig\Loader\ChainLoader([$loader1, $loader2]);

$twig = new \Twig\Environment($loader);

When looking for a template, Twig tries each loader in turn and returns as soon
as the template is found. When rendering the ``index.html`` template from the
above example, Twig will load it with ``$loader2`` but the ``base.html``
as the template is found. When rendering the ``index.html.twig`` template from the
above example, Twig will load it with ``$loader2`` but the ``base.html.twig``
template will be loaded from ``$loader1``.

.. note::
Expand Down
20 changes: 10 additions & 10 deletions doc/functions/include.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The ``include`` function returns the rendered content of a template:

.. code-block:: twig
{{ include('template.html') }}
{{ include('template.html.twig') }}
{{ include(some_var) }}
Included templates have access to the variables of the active context.
Expand All @@ -18,44 +18,44 @@ additional variables:

.. code-block:: twig
{# template.html will have access to the variables from the current context and the additional ones provided #}
{{ include('template.html', {name: 'Fabien'}) }}
{# template.html.twig will have access to the variables from the current context and the additional ones provided #}
{{ include('template.html.twig', {name: 'Fabien'}) }}
You can disable access to the context by setting ``with_context`` to
``false``:

.. code-block:: twig
{# only the name variable will be accessible #}
{{ include('template.html', {name: 'Fabien'}, with_context = false) }}
{{ include('template.html.twig', {name: 'Fabien'}, with_context = false) }}
.. code-block:: twig
{# no variables will be accessible #}
{{ include('template.html', with_context = false) }}
{{ include('template.html.twig', with_context = false) }}
And if the expression evaluates to a ``\Twig\Template`` or a
``\Twig\TemplateWrapper`` instance, Twig will use it directly::

// {{ include(template) }}

$template = $twig->load('some_template.twig');
$template = $twig->load('some_template.html.twig');

$twig->display('template.twig', ['template' => $template]);
$twig->display('template.html.twig', ['template' => $template]);

When you set the ``ignore_missing`` flag, Twig will return an empty string if
the template does not exist:

.. code-block:: twig
{{ include('sidebar.html', ignore_missing = true) }}
{{ include('sidebar.html.twig', ignore_missing = true) }}
You can also provide a list of templates that are checked for existence before
inclusion. The first template that exists will be rendered:

.. code-block:: twig
{{ include(['page_detailed.html', 'page.html']) }}
{{ include(['page_detailed.html.twig', 'page.html.twig']) }}
If ``ignore_missing`` is set, it will fall back to rendering nothing if none
of the templates exist, otherwise it will throw an exception.
Expand All @@ -65,7 +65,7 @@ When including a template created by an end user, you should consider

.. code-block:: twig
{{ include('page.html', sandboxed: true) }}
{{ include('page.html.twig', sandboxed: true) }}
Arguments
---------
Expand Down
4 changes: 2 additions & 2 deletions doc/functions/parent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parent block when overriding a block by using the ``parent`` function:

.. code-block:: html+twig

{% extends "base.html" %}
{% extends "base.html.twig" %}

{% block sidebar %}
<h3>Table Of Contents</h3>
Expand All @@ -15,7 +15,7 @@ parent block when overriding a block by using the ``parent`` function:
{% endblock %}

The ``parent()`` call will return the content of the ``sidebar`` block as
defined in the ``base.html`` template.
defined in the ``base.html.twig`` template.

.. seealso::

Expand Down
4 changes: 2 additions & 2 deletions doc/functions/source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ The ``source`` function returns the content of a template without rendering it:

.. code-block:: twig
{{ source('template.html') }}
{{ source('template.html.twig') }}
{{ source(some_var) }}
When you set the ``ignore_missing`` flag, Twig will return an empty string if
the template does not exist:

.. code-block:: twig
{{ source('template.html', ignore_missing = true) }}
{{ source('template.html.twig', ignore_missing = true) }}
The function uses the same template loaders as the ones used to include
templates. So, if you are using the filesystem loader, the templates are looked
Expand Down
2 changes: 1 addition & 1 deletion doc/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ filesystem loader::
'cache' => '/path/to/compilation_cache',
]);

echo $twig->render('index.html', ['name' => 'Fabien']);
echo $twig->render('index.html.twig', ['name' => 'Fabien']);

.. _`SymfonyCasts Twig Tutorial`: https://symfonycasts.com/screencast/twig
8 changes: 4 additions & 4 deletions doc/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ the request is made via Ajax and choose the layout accordingly:

.. code-block:: twig
{% extends request.ajax ? "base_ajax.html" : "base.html" %}
{% extends request.ajax ? "base_ajax.html.twig" : "base.html.twig" %}
{% block content %}
This is the content to be displayed.
Expand All @@ -80,17 +80,17 @@ instance, the name can depend on the value of a variable:

.. code-block:: twig
{% include var ~ '_foo.html' %}
{% include var ~ '_foo.html.twig' %}
If ``var`` evaluates to ``index``, the ``index_foo.html`` template will be
If ``var`` evaluates to ``index``, the ``index_foo.html.twig`` template will be
rendered.

As a matter of fact, the template name can be any valid expression, such as
the following:

.. code-block:: twig
{% include var|default('index') ~ '_foo.html' %}
{% include var|default('index') ~ '_foo.html.twig' %}
Overriding a Template that also extends itself
----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/sandbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function:

.. code-block:: twig
{{ include('user.html', sandboxed: true) }}
{{ include('user.html.twig', sandboxed: true) }}
You can sandbox all templates by passing ``true`` as the second argument of
the extension constructor::
Expand Down
32 changes: 16 additions & 16 deletions doc/tags/include.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ of that file:

.. code-block:: twig
{% include 'header.html' %}
{% include 'header.html.twig' %}
Body
{% include 'footer.html' %}
{% include 'footer.html.twig' %}
.. note::

Expand All @@ -25,17 +25,17 @@ of that file:
{# Store a rendered template in a variable #}
{% set content %}
{% include 'template.html' %}
{% include 'template.html.twig' %}
{% endset %}
{# vs #}
{% set content = include('template.html') %}
{% set content = include('template.html.twig') %}
{# Apply filter on a rendered template #}
{% apply upper %}
{% include 'template.html' %}
{% include 'template.html.twig' %}
{% endapply %}
{# vs #}
{{ include('template.html')|upper }}
{{ include('template.html.twig')|upper }}
* The ``include`` function does not impose any specific order for
arguments thanks to :ref:`named arguments <named-arguments>`.
Expand All @@ -49,23 +49,23 @@ You can add additional variables by passing them after the ``with`` keyword:

.. code-block:: twig
{# template.html will have access to the variables from the current context and the additional ones provided #}
{% include 'template.html' with {'name': 'Fabien'} %}
{# template.html.twig will have access to the variables from the current context and the additional ones provided #}
{% include 'template.html.twig' with {'name': 'Fabien'} %}
{% set vars = {'name': 'Fabien'} %}
{% include 'template.html' with vars %}
{% include 'template.html.twig' with vars %}
You can disable access to the context by appending the ``only`` keyword:

.. code-block:: twig
{# only the name variable will be accessible #}
{% include 'template.html' with {'name': 'Fabien'} only %}
{% include 'template.html.twig' with {'name': 'Fabien'} only %}
.. code-block:: twig
{# no variables will be accessible #}
{% include 'template.html' only %}
{% include 'template.html.twig' only %}
.. tip::

Expand All @@ -78,7 +78,7 @@ The template name can be any valid Twig expression:
.. code-block:: twig
{% include some_var %}
{% include ajax ? 'ajax.html' : 'not_ajax.html' %}
{% include ajax ? 'ajax.html.twig' : 'not_ajax.html.twig' %}
And if the expression evaluates to a ``\Twig\Template`` or a
``\Twig\TemplateWrapper`` instance, Twig will use it directly::
Expand All @@ -95,16 +95,16 @@ placed just after the template name. Here some valid examples:

.. code-block:: twig
{% include 'sidebar.html' ignore missing %}
{% include 'sidebar.html' ignore missing with {'name': 'Fabien'} %}
{% include 'sidebar.html' ignore missing only %}
{% include 'sidebar.html.twig' ignore missing %}
{% include 'sidebar.html.twig' ignore missing with {'name': 'Fabien'} %}
{% include 'sidebar.html.twig' ignore missing only %}
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:: twig
{% include ['page_detailed.html', 'page.html'] %}
{% include ['page_detailed.html.twig', 'page.html.twig'] %}
If ``ignore missing`` is given, it will fall back to rendering nothing if none
of the templates exist, otherwise it will throw an exception.
2 changes: 1 addition & 1 deletion doc/tags/sandbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template, when sandboxing is not enabled globally for the Twig environment:
.. code-block:: twig
{% sandbox %}
{% include 'user.html' %}
{% include 'user.html.twig' %}
{% endsandbox %}
.. warning::
Expand Down
Loading

0 comments on commit 0365afe

Please sign in to comment.