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
正如我現在的回答所反映的那樣,我錯過了你的「天」鍵是一個包含散列而不是單個級別的數組。現在應該這樣做。 –