如何循环使用YAML frontmatter内容以便在Liquid中使用?(How to loop through YAML frontmatter content for use in Liquid

编程入门 行业动态 更新时间:2024-10-28 04:25:40
如何循环使用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 %}

更多推荐

本文发布于:2023-08-06 09:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1447802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   frontmatter   YAML   Liquid   Jekyll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!