I have content which needs to go into a certain column so I have a field called 'column' there. I can create the array I want by hand:
{%
set items = {
1 : {
0 : 'Quick Facts',
1 : 'Agencies'
},
2 : {
0 : 'Inspiration',
1 : 'Industry Experience'
}
}
%}
Where 1 and 2 are the columns, and 0,1 is just a normal index. In a loop it is different. I have tried the same syntax but of course setting the variable in the loop will set the new variable every time and replace the old one. Using merge like below always gives me new keys. Is there a way to do this as easily as PHP?
{% set blocks = {} %}
{% for tab in tabs %}
{% for key,block in tab.tabItem %}
{% if block.type == 'about' %}
{% set blocks = blocks|merge({ (block.column.value) : block.aboutTitle}) %}
{% endif %}
{% endfor %}
{% endfor %}
This is the output of the two pieces of code (first being what I want). I'd like the block.column.value
to be the key.
merge
using a hash, my understanding is that it will replace (rather than append) any values that share the same hash key. So it would be impossible to do what your asking using a single loop/set statement. Can you perhaps share the loop that you are using also?block.column.value
isn't being used.{% set blocks = blocks|merge({ ('col'~block.column.value) : block.aboutTitle }) %}