在 Jekyll 中,我想遍历列表中的项目并为每个项目设置分配标签
In Jekyll, I want to loop through items in a list and set assign tags for each item
在 Jekyll 中,我想遍历列表中的项目并为每个项目分配变量。
在数据文件中,我的列表如下所示:
entries:
- title: Sidebar
subcategories:
- title: Overview
items:
- title: Introduction
url: /introduction/
linkname: intro
- title: Release Notes
url: /release_notes/
linkname: relnote
我的循环逻辑是这样的:
{% for entry in sidebar %}
{% for subcategory in entry.subcategories %}
{% for item in subcategory.items %}
{% assign item.linkname = "<a href="{{ /item.permalink | prepend: site.baseurl}}">{{item.title}}</a>" %}
{% endfor %}
{% endfor %}
{% endfor %}
然后我想在页面上使用 {{intro}} 或 {{relnote}} 插入变量。使用这种方法,我应该能够为侧边栏中的所有项目生成变量,从而轻松地将链接嵌入到我的内容中。
不过,这个方法好像不行。当我插入它时,变量没有任何显示。我做错了什么?
使用 Jekyll/Liquid,您无法从变量值创建变量名。
在 Jekyll 中,我想遍历列表中的项目并为每个项目分配变量。
在数据文件中,我的列表如下所示:
entries:
- title: Sidebar
subcategories:
- title: Overview
items:
- title: Introduction
url: /introduction/
linkname: intro
- title: Release Notes
url: /release_notes/
linkname: relnote
我的循环逻辑是这样的:
{% for entry in sidebar %}
{% for subcategory in entry.subcategories %}
{% for item in subcategory.items %}
{% assign item.linkname = "<a href="{{ /item.permalink | prepend: site.baseurl}}">{{item.title}}</a>" %}
{% endfor %}
{% endfor %}
{% endfor %}
然后我想在页面上使用 {{intro}} 或 {{relnote}} 插入变量。使用这种方法,我应该能够为侧边栏中的所有项目生成变量,从而轻松地将链接嵌入到我的内容中。
不过,这个方法好像不行。当我插入它时,变量没有任何显示。我做错了什么?
使用 Jekyll/Liquid,您无法从变量值创建变量名。