Skip to content

Commit

Permalink
Add documentation for types tag and extend CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
drjayvee committed Aug 26, 2024
1 parent e06d15b commit 0b51a14
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Bump minimum PHP version to 8.0
* Fix integration tests when a test has more than one data/expect section and deprecations
* Add the `enum_cases` function
* Add the `types` tag

# 3.11.0 (2024-08-08)

Expand Down
1 change: 1 addition & 0 deletions doc/tags/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Tags
macro
sandbox
set
types
use
verbatim
with
30 changes: 30 additions & 0 deletions doc/tags/types.rst
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.

0 comments on commit 0b51a14

Please sign in to comment.