mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 20:16:45 +00:00
minor #4362 Document Twig vs PHP types (fabpot)
This PR was merged into the 3.x branch.
Discussion
----------
Document Twig vs PHP types
Refs #4256
Commits
-------
9690e7bbbf Document Twig vs PHP types
This commit is contained in:
+18
-2
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user