Skip to content

Commit

Permalink
minor #4362 Document Twig vs PHP types (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Document Twig vs PHP types

Refs #4256

Commits
-------

9690e7b Document Twig vs PHP types
  • Loading branch information
fabpot committed Sep 30, 2024
2 parents 6980344 + 9690e7b commit a16053b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions doc/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,24 @@ 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:

=================== ===============================
Twig Type PHP Type
=================== ===============================
string A string or a Stringable object
number An integer or a float
boolean ``true`` or ``false``
null ``null``
iterable (mapping) An array
iterable (sequence) An array
iterable (object) An iterable object
object An object
=================== ===============================

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

.. code-block:: twig
Expand Down

0 comments on commit a16053b

Please sign in to comment.