液体for循环能否在Jekyll中包含页面变量? [英] Can a liquid for loop contain a page variable in Jekyll?
问题描述
比方说,我有一堆_data
文件,可用于创建特定页面的列表.具有这些列表的所有页面的自定义前端变量为pageName
. pageName
的值恰好与_data
文件与列表匹配.
Let's say I have a bunch of _data
files that I use to create a list for specific pages. All of the pages that have these lists have a custom front matter variable of pageName
. The value of pageName
just so happens to match the _data
file with the list.
我不想使用html代码块粘贴到每个页面中,而是想使用include
提取通用html代码块.为此,包含必须动态或包含液体标记才能动态.
Rather than pasting the html blocks of code into each page, I'd like to use an include
to pull in a generic block of html. To do that, the include has to be dynamic or contain liquid markup to become dynamic.
这可能是您需要的更多上下文,但是我的问题归结为这一点,这可能是这样的:
That might be more context than you need, but my question boils down to this, is something like this possible:
{% for item in site.data.{{page.pageName}} %}
{{ item.label }}
{% endfor %}
除非我丢失了某些东西,否则这将无法正常工作,因此我想知道是否存在一种实现类似功能的方法.
Unless I'm missing something, this doesn't work so I'm wanting to know if there's a way of achieving similar functionality.
我发现了这个类似的问题,但是似乎并没有回答它是否可用于访问页面变量以构建文件名.
I found this similar question, but it doesn't seem to answer whether it can be used to access a page variable to build a file name.
推荐答案
您可以使用像这样的方括号表示法:
You can use the bracket notation like this :
{% for item in site.data[page.pageName] %}
这篇关于液体for循环能否在Jekyll中包含页面变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!