Skip to content

Commit

Permalink
Documentation for types tag uses Twig types in examples instead of PHP
Browse files Browse the repository at this point in the history
Specifically, "bool" => "boolean" and "int" => "number".

This aligns the `types` documentation with templates.rst. See twigphp#4362

Thanks, @alexander-schranz!
  • Loading branch information
drjayvee committed Oct 21, 2024
1 parent bcceaa3 commit 4d5be0d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions doc/tags/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ The ``types`` tag declares the types of template variables.

To do this, specify a :ref:`mapping <twig-expressions>` of names to their types as strings.

Here is how to declare that ``is_correct`` is a boolean, while ``score`` is an
integer (see note below):
Here is how to declare that ``is_correct`` is a boolean, while ``score`` is a number (see note below):

.. code-block:: twig
{% types {
is_correct: 'bool',
score: 'int',
is_correct: 'boolean',
score: 'number',
} %}
You can declare variables as optional by adding the ``?`` suffix:

.. code-block:: twig
{% types {
is_correct: 'bool',
score?: 'int',
is_correct: 'boolean',
score?: 'number',
} %}
By default, this tag does not affect the template compilation or runtime behavior.
Expand Down

0 comments on commit 4d5be0d

Please sign in to comment.