Skip to content

Commit

Permalink
Document Twig vs PHP types
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 29, 2024
1 parent 191a138 commit 530480e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions doc/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,18 @@ Twig templates have access to variables provided by the PHP application and
variables created in templates via the :doc:`set <tags/set>` tag. These
variables can be manipulated and displayed in the template.

Use a dot (``.``) to access attributes of a variable (methods, properties
or constants of a PHP object, or items of a PHP array):
Twig tries to abstract PHP types as much as possible and works with a few basic
types, supported by ``filters``, ``functions``, and ``tests`` among others:

* ``string``: A sequence of characters;
* ``number``: An integer or a float;
* ``iterable``: A sequence, a mapping, or an iterable object;
* ``object``: A structure supporting method calls;
* ``boolean``: ``true`` or ``false``;
* ``null``: The special ``null`` value.

The ``iterable`` and ``object`` types expose attributes you can access via the
dot (``.``) operator:

.. code-block:: twig
Expand Down

0 comments on commit 530480e

Please sign in to comment.