Skip to content

Commit

Permalink
Merge branch '3.x' into 4.x
Browse files Browse the repository at this point in the history
* 3.x:
  Documentation for types tag uses Twig types in examples instead of PHP
  • Loading branch information
fabpot committed Oct 23, 2024
2 parents 99a85a7 + f43eba5 commit 3663fa6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions doc/tags/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,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
2 changes: 1 addition & 1 deletion src/TokenParser/TypesTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Declare variable types.
*
* {% types {foo: 'int', bar?: 'string'} %}
* {% types {foo: 'number', bar?: 'string'} %}
*
* @author Jeroen Versteeg <[email protected]>
*
Expand Down
4 changes: 2 additions & 2 deletions tests/Node/TypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class TypesTest extends NodeTestCase
{
private static function getValidMapping(): array
{
// {foo: 'string', bar?: 'int'}
// {foo: 'string', bar?: 'number'}
return [
'foo' => [
'type' => 'string',
'optional' => false,
],
'bar' => [
'type' => 'int',
'type' => 'number',
'optional' => true,
],
];
Expand Down

0 comments on commit 3663fa6

Please sign in to comment.