简体   繁体   中英

How to read an array in twig

I have an array of json composed this way :

[{"name":K,"age":14,"job":null}]

I want to know have to read it in twig. I've tried so many solution like those:

array|json_encode()
array|raw
{{ attribute(array, item) }}

But no one of those solutions are working

Thanks

you can simply iterate the json without any preparements

[{"name":K,"age":14,"job":null},{"name":K,"age":17,"job":null}]


{% for key, value in array %}
   {{ value.age ~ "-" }}
{% endfor %}

prints 14-17-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM