如何循环使用YAML frontmatter内容以便在Liquid中使用?(How to loop through YAML frontmatter content for use in Liquid? (Jekyll))
我试图在我的frontmatter的sidebar属性中循环一些值,以便在一些也使用YAML的Liquid循环中使用,但它不起作用。
这是代码:
--- sidebar: [a, b, c] --- {% for sidebar in page.sidebar %} {% for entry in sidebar.entries %} ...我希望代码使用a.entries,然后是b.entries,然后是c.entries,但是它不起作用。 是因为所有的YAML处理都是同时发生的,然后Jekyll管道流程转移到HTML或其他东西?
I'm trying to loop through some values in my frontmatter's sidebar property to use in some Liquid loops that also make use of YAML, but it's not working.
Here's the code:
--- sidebar: [a, b, c] --- {% for sidebar in page.sidebar %} {% for entry in sidebar.entries %} ...I want the code to use a.entries, and then b.entries, and then c.entries, but it's not working. Is that because all the YAML processing happens at once, and then the Jekyll pipeline process moves on to HTML or something?
最满意答案
这就是您可以使用变量名访问数据文件的方法:
{% for sidebar in page.sidebar %} {% for entry in site.data.sidebars[sidebar].entries %} .. do things with datas {% endfor %} {% endfor %}That's how you can access a data file with a variable name :
{% for sidebar in page.sidebar %} {% for entry in site.data.sidebars[sidebar].entries %} .. do things with datas {% endfor %} {% endfor %}更多推荐
发布评论