gpt4 book ai didi

yaml - 带有嵌套元素的 Jekyll YAML 文件

转载 作者:行者123 更新时间:2023-12-02 08:31:32 26 4
gpt4 key购买 nike

我想访问我的“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 %}

最佳答案

1。您的数据文件有误 您的 locales.enlocales.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

2。数据文件名

如果您的数据文件名为 benefit.yml,您可以使用 site.data.benefit.locales.drink 访问您的数据

3。你的循环是错误的

然后循环给你类似的东西:

benefit = Array
["en",{"title"=>"Drink", "detail"=>"The fridg...!", "icon"=>"benefit2.png"}]

其中 benefit[0] = enbenefit[1] = hash{"title"=>"Drink", "detail"=>"The fridg...!", "icon"=>"benefit2.png"}

如果你想在此处访问数据,你可以执行 {{ benefit[1].title }}

游戏语言环境的完整代码:

{% 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 %}

关于yaml - 带有嵌套元素的 Jekyll YAML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26253071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com