Jekyll 遍历三维数组
Jekyll iterate over a triple dimension array
我使用 Jekyll 3.3 在 _config.yml
文件中创建了一个数组:
profiles:
- user1:
- username: "test"
- link: "http://test.test"
我想获取每个用户的值 username
和 link
。所以我使用双循环:
{% for profile in site.profiles %}
{% for user in profile %}
{{ user.username }}
{% endfor %}
{% endfor %}
但这并没有打印出任何东西,我是不是漏掉了什么?
数据排列如下:
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 %}
我使用 Jekyll 3.3 在 _config.yml
文件中创建了一个数组:
profiles:
- user1:
- username: "test"
- link: "http://test.test"
我想获取每个用户的值 username
和 link
。所以我使用双循环:
{% for profile in site.profiles %}
{% for user in profile %}
{{ user.username }}
{% endfor %}
{% endfor %}
但这并没有打印出任何东西,我是不是漏掉了什么?
数据排列如下:
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 %}