ceba96b05ba853bfbb7f4ef48e9472bd5ec0498a
[yaffs-website] / vendor / twig / twig / doc / functions / attribute.rst
1 ``attribute``
2 =============
3
4 .. versionadded:: 1.2
5     The ``attribute`` function was added in Twig 1.2.
6
7 The ``attribute`` function can be used to access a "dynamic" attribute of a
8 variable:
9
10 .. code-block:: jinja
11
12     {{ attribute(object, method) }}
13     {{ attribute(object, method, arguments) }}
14     {{ attribute(array, item) }}
15
16 In addition, the ``defined`` test can check for the existence of a dynamic
17 attribute:
18
19 .. code-block:: jinja
20
21     {{ attribute(object, method) is defined ? 'Method exists' : 'Method does not exist' }}
22
23 .. note::
24
25     The resolution algorithm is the same as the one used for the ``.``
26     notation, except that the item can be any valid expression.