0
我在Twig数组中嵌套了内容。我有个月,每个有天:用树枝在循环内打印循环?
在我page.twig:
{% set mock = {
main_title: 'Main title',
months:
[
{
sub_title: 'Title 1',
days: [
{
monday: 'Lorum',
tuesday: 'Ipsum'
}
]
},
{
sub_title: 'Title 2',
days: [
{
monday: 'Dolorem',
tuesday: 'Neque'
}
]
}
]
}
%}
{% include "component.twig" %}
我试图打印每个月的子标题和文本当天在它之下:
<h2>Title 1</h2>
<h3>Lorum</h3>
<h3>Ipsum</h3>
<h2>Title 2</h2>
<h3>Dolorem</h3>
<h3>Neque</h3>
在component.twig:
{% for m in months %}
<h2>{{ m.sub_title }}</h2>
{% for d in months.days %}
<h3>Print test</h3>
{% endfor %}
{% endfor %}
月份在<h2>
sub_title是印刷精美,但我甚至不能GE t几个月中的日子可以正确循环。
这不,但现在只打印H3星期一,不是所有的日子。 – Evans
正如我现在的回答所反映的那样,我错过了你的“天”键是一个包含散列而不是单个级别的数组。现在应该这样做。 –