attribute¶
New in version 1.2: The attribute function was added in Twig 1.2.
attribute can be used to access a "dynamic" attribute of a variable:
1 2 3 | {{ attribute(object, method) }}
{{ attribute(object, method, arguments) }}
{{ attribute(array, item) }}
|
{% for column in columns %} {% if column=='activity' %} {% for activity in company.activity %} {% endfor %} {% else if column='contacts' %} {% for contact in company.contacts %} {% endfor %} {% else %} {{ attribute(company, column) }} {% endif %} {% endfor %}
评论
发表评论