From 530480efab39776181e843b6ccba1b91fd2e8a58 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 29 Sep 2024 18:29:35 +0200 Subject: [PATCH] Document Twig vs PHP types --- doc/templates.rst | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/templates.rst b/doc/templates.rst index 6626d4ee896..6c19161eaf3 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -76,8 +76,18 @@ Twig templates have access to variables provided by the PHP application and variables created in templates via the :doc:`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