2016-11-28 62 views
1

使用傑基爾3.3我創建一個數組到_config.yml文件:傑基爾遍歷一個三合一維數組

profiles: 
    - user1: 
    - username: "test" 
    - link: "http://test.test" 

我想每個用戶的價值usernamelink。所以我使用雙循環:

{% for profile in site.profiles %} 
    {% for user in profile %} 
     {{ user.username }} 
    {% endfor %} 
{% endfor %} 

但是,這並不打印任何東西,我錯過了什麼?

回答

3

隨着DATAS安排是這樣的:

profiles: 
    - username: "test" 
    link: "http://test.test" 
    - username: "test2" 
    link: "http://test.test2" 

你可以這樣做:

{% for user in site.profiles %} 
    <a href="{{ user.link }}">{{ user.username }}</a> 
{% endfor %}