Document Twig vs PHP types

This commit is contained in:
Fabien Potencier
2024-09-29 18:29:35 +02:00
parent 191a138768
commit 9690e7bbbf
+18 -2
View File
@@ -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