blob: e9d9a842ef3c5fb1a3bdfe3de3b5ab098ef1f429 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``attribute``
2=============
3
4The ``attribute`` function can be used to access a "dynamic" attribute of a
5variable:
6
7.. code-block:: twig
8
9 {{ attribute(object, method) }}
10 {{ attribute(object, method, arguments) }}
11 {{ attribute(array, item) }}
12
13In addition, the ``defined`` test can check for the existence of a dynamic
14attribute:
15
16.. code-block:: twig
17
18 {{ attribute(object, method) is defined ? 'Method exists' : 'Method does not exist' }}
19
20.. note::
21
22 The resolution algorithm is the same as the one used for the ``.``
23 notation, except that the item can be any valid expression.