Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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