Documentation for types tag uses Twig types in examples instead of PHP

This commit is contained in:
Jeroen Versteeg
2024-10-21 09:38:42 +02:00
committed by Fabien Potencier
parent bcceaa3468
commit f3e0a00cf0
3 changed files with 8 additions and 9 deletions
+5 -6
View File
@@ -9,14 +9,13 @@ 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:
@@ -24,8 +23,8 @@ 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.
+1 -1
View File
@@ -20,7 +20,7 @@ use Twig\TokenStream;
/**
* Declare variable types.
*
* {% types {foo: 'int', bar?: 'string'} %}
* {% types {foo: 'number', bar?: 'string'} %}
*
* @author Jeroen Versteeg <jeroen@alisqi.com>
*
+2 -2
View File
@@ -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,
],
];