我在用Twig PatternLab。
我在JSON和一个Twig for循环中遇到了一个小问题。
Atom 00-h3-black.twig:
<h3 class="A-ChevronBlack"><a href="">{{ text.chevron }}</a></h3>分子00- Molecule tile.twig:
<div class="M-DMasterTile">
<div class="image"></div>
<div class="content">
{% include "atoms-h3-black" %}
</div>
</div>有机体00-default2.twig:
{% for post in default2 %}
{% include "molecules-mastertile" %}
{% endfor %}和JSON在有机体文件夹00-default2.json中
{
"default2" : [
{
"text" : {
"chevron" : "How to build a campfire",
"body" : "This is the body copy"
}
},
{
"text" : {
"chevron":"Lorem Ipsum",
"body" : "This is the body copy"
}
}
]
}我的期望是让"default2“循环两次,因为我在JSON中有一个包含2个项目的数组,并推送JSON内容。如果我从JSON数组中取出变量,它会显示更改(但显然是重复的)。
我在这里做错了什么?
非常感谢你的帮助
发布于 2017-07-30 00:15:10
include使用全局作用域,并且其中没有变量text。使用include with语法将变量传递到内部作用域。
您的Organisms 00-default2.twig应该如下所示:
{% for post in default2 %}
{% include "molecules-mastertile" with {'text': post.text} %}
{% endfor %}https://stackoverflow.com/questions/45391036
复制相似问题