Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``attribute`` |
| 2 | ============= |
| 3 | |
| 4 | The ``attribute`` function can be used to access a "dynamic" attribute of a |
| 5 | variable: |
| 6 | |
| 7 | .. code-block:: twig |
| 8 | |
| 9 | {{ attribute(object, method) }} |
| 10 | {{ attribute(object, method, arguments) }} |
| 11 | {{ attribute(array, item) }} |
| 12 | |
| 13 | In addition, the ``defined`` test can check for the existence of a dynamic |
| 14 | attribute: |
| 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. |