2017-03-15 64 views
0

不循環我有一個名爲gallery.yml一個在我的哲基爾的項目稱爲/_data文件夾中的頁面,我想通過組迴路gallery.yml並在一個新的頁面輸出的/_includes數據/ YAML環路傑基爾

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 

.html頁面/_includes

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

但是當我申請這個,沒有循環 - 它只是重複了第一組。任何提示,我要去哪裏錯了?

回答

1

for標記用於遍歷數組並返回數組中的每個項。

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

+0

我明白了!謝謝! – bunnycode