[英]Jekyll YAML file with nested elements
我想访问“ benefit.yml”文件中的嵌套元素,并使用循环调用这些元素。 但是它不起作用,什么也没有出现。
这是我的“ benefit.yml”:
locales:
en:
title: "Games"
detail: "To relax and take breaks during the day, we play football, table tennis and Xbox"
icon: benefit1.png
fr:
title: "Jeux"
detail: "To relax and take breaks during the day, we play football, table tennis and Xbox"
icon: benefit1.png
en:
title: "Drink"
detail: "The fridge is full of beer cans and Coca-Cola, Ice Tea and coffee. You can drink whatever makes you happy, all day!"
icon: benefit2.png
fr:
title: "Boissons"
detail: "The fridge is full of beer cans and Coca-Cola, Ice Tea and coffee. You can drink whatever makes you happy, all day!"
icon: benefit2.png
这是我的循环:
{% for benefit in site.data.benefits.locales.en %}
<div class="s-column6">
<div class="kiwup-benefit pb1 mb1">
<img src="/image/benefit/{{ benefit.icon }}" alt="kiwuper">
<div class="kiwup-benefit-info">
<h3 class="h4-like text-dark">{{ benefit.title }}</h3>
<p>{{ benefit.detail }}</p>
</div>
</div>
</div>
{% endfor %}
locales.en
和locales.fr
条目重叠。 正确的嵌套可以是: 语言环境:
games:
en:
title: "Games"
detail: "To relax and take breaks during the day, we play football, table tennis and Xbox"
icon: benefit1.png
fr:
title: "Jeux"
detail: "To relax and take breaks during the day, we play football, table tennis and Xbox"
icon: benefit1.png
drink:
en:
title: "Drink"
detail: "The fridge is full of beer cans and Coca-Cola, Ice Tea and coffee. You can drink whatever makes you happy, all day!"
icon: benefit2.png
fr:
title: "Boissons"
detail: "The fridge is full of beer cans and Coca-Cola, Ice Tea and coffee. You can drink whatever makes you happy, all day!"
icon: benefit2.png
如果您的数据文件名是benefit.yml你访问你的DATAS site.data.benefit.locales.drink
然后循环给你类似:
benefit = Array
["en",{"title"=>"Drink", "detail"=>"The fridg...!", "icon"=>"benefit2.png"}]
其中benefit[0] = en
和benefit[1] = hash{"title"=>"Drink", "detail"=>"The fridg...!", "icon"=>"benefit2.png"}
如果您想在此处访问数据,可以执行{{ benefit[1].title }}
games
语言环境的完整代码:
{% for benefit in site.data.benefit.locales.games %}
<div class="s-column6">
<div class="kiwup-benefit pb1 mb1">
<img src="/image/benefit/{{ benefit[1].icon }}" alt="kiwuper">
<div class="kiwup-benefit-info">
<h3 class="h4-like text-dark">{{ benefit[1].title }}</h3>
<p>{{ benefit[1].detail }}</p>
</div>
</div>
</div>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.