-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for types tag and extend CHANGELOG
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ Tags | |
macro | ||
sandbox | ||
set | ||
types | ||
use | ||
verbatim | ||
with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
``types`` | ||
======= | ||
|
||
The ``types`` tag declares the types for one or more names variables. | ||
|
||
To do this, specify a :ref:`mapping<twig-expressions>`) of names to their types as string constants. | ||
|
||
Here is how you declare that variable ``foo`` is a boolean, while ``bar`` is an integer (see note below): | ||
|
||
.. code-block:: twig | ||
{% types { | ||
foo: 'bool', | ||
bar: 'int', | ||
} %} | ||
You may put these all on one line. However, using one line per variable improves readability. | ||
|
||
This tag has no effect on the template's output or runtime behavior. | ||
|
||
Its purpose is to enable designers and developers to document and specify the context's available | ||
and/or required variables. | ||
|
||
Additionally, :ref:`Twig extensions<twig-extensions>` can analyze these tags to perform compile-time and | ||
runtime analysis of templates in order to increase code quality. | ||
|
||
.. note:: | ||
|
||
The syntax for and contents of type strings are intentionally left out of scope. | ||
|