symfony - Join property values of a list of objects in twig -
is possible join values of properties of list of objects displaying it?
like:
{{ users|join(', ', username) }} where users objects, having getusername() method.
suppose join doesn't take additional argument, there workaround achieve similar? can not use __tostring() function, represents else...
you use..
{% set usernames = [] %} {% user in users %} {% set usernames = usernames|merge([user.username]) %} {% endfor %} {{ usernames|join(', ') }} not prettiest though.
you make custom twig filter it.
Comments
Post a Comment