Data/YAML 循环不在 Jekyll 中循环
Data/YAML loop not looping in Jekyll
我的 Jekyll 项目中名为 /_data
的文件夹中有一个名为 gallery.yml
的页面,我想遍历 gallery.yml
中的组并将输出放在/_includes
.
中的新页面
gallery.yml
:
- name: Banana Shortcake
color: yellow
weight: 2 lbs
- name: Chocolate Mousse
color: brown
weight: 9 lbs
rogue-item: Yum!
- name: Strawberry Fluff
color: pink
weight: 0.5 oz
/_includes
中的.html
页面:
{% for gallery in site.data.gallery %}
<h1>{{ gallery.name }}</h1><!-- This should be Banana Shortcake -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
<h1>{{ gallery.name }}</h1><!-- This should be Chocolate Mousse -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
<p>Rating: {{ gallery.rogue-item }}</p>
<h1>{{ gallery.name }}</h1><!-- This should be Strawberry Fluff -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
{% endfor %}
但是当我应用这个时,没有循环——它只是重复第一个分组。关于我哪里出错的任何提示?
for
标签用于遍历数组,return 用于数组中的每一项。
{% for gallery in site.data.gallery %}
<h1>{{ gallery.name }}</h1><!-- This should be Banana Shortcake -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
{% endfor %}
会自动运行3次输出需要的HTML。
我的 Jekyll 项目中名为 /_data
的文件夹中有一个名为 gallery.yml
的页面,我想遍历 gallery.yml
中的组并将输出放在/_includes
.
gallery.yml
:
- name: Banana Shortcake
color: yellow
weight: 2 lbs
- name: Chocolate Mousse
color: brown
weight: 9 lbs
rogue-item: Yum!
- name: Strawberry Fluff
color: pink
weight: 0.5 oz
/_includes
中的.html
页面:
{% for gallery in site.data.gallery %}
<h1>{{ gallery.name }}</h1><!-- This should be Banana Shortcake -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
<h1>{{ gallery.name }}</h1><!-- This should be Chocolate Mousse -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
<p>Rating: {{ gallery.rogue-item }}</p>
<h1>{{ gallery.name }}</h1><!-- This should be Strawberry Fluff -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
{% endfor %}
但是当我应用这个时,没有循环——它只是重复第一个分组。关于我哪里出错的任何提示?
for
标签用于遍历数组,return 用于数组中的每一项。
{% for gallery in site.data.gallery %}
<h1>{{ gallery.name }}</h1><!-- This should be Banana Shortcake -->
<p>The color of {{ gallery.name }} is {{ gallery.color }}, and its weight is {{ gallery.weight }}</p>
{% endfor %}
会自动运行3次输出需要的HTML。