【发布时间】:2016-04-29 13:14:45
【问题描述】:
我在 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 打印正常,但我什至无法让月份中的日期正确循环。
【问题讨论】:
标签: twig