I can't find the way to parse an array with a generate key with Twig :
My object post :
[blocks_content_0_title] => Title0
[blocks_content_1_title] => Title1
[blocks_content_2_title] => Title3
My question is, how to insert a variable in key ?
{{ post.blocks_content_~myNumber~_title }}
{{ post['blocks_content_'~myNumber~'_title'] }}
Try using attribute()
:
{{ attribute(post, 'blocks_content_' ~ myNumber ~ '_title') }}
http://twig.sensiolabs.org/doc/2.x/functions/attribute.html
Personally, I'd consider refactoring so I don't have to do this in a template.