在 Jekyll 中,如何在另一个集合的布局中使用变量的子类别?
In Jekyll, how can I use subcategories of a variable in the layout of another collection?
我有一个项目集。每个项目的一部分是参与该项目的人员列表:
---
layout: project
name: Important Project
participants:
- name: julia
role: owner
- name: paul
role: manager
- name: chris
role: implementer
---
这些人中的每个人自己都在一个集合中,并且有一个页面列出了他们的详细信息。我想包括他们一直在从事的项目以及他们的角色。这是我的最大努力,但没有用:
{% for project in site.projects %}
{% if project.participants['name'] == {{ page.name }} %}
<p>{{ project.name }} - {{ project.participants['role'] }}</p>
{% endif %}
{% endfor %}
欢迎提出任何建议。
假设这个结构:
# _config.yml
collections:
- people
- projects
然后目录结构如下:
_projects/project1.md
_people/person1.md
_people/person2.md
和person1.mdfront-matter喜欢:
---
name: julia
---
还有上面front-matter你提供的,这是如何显示每个人的项目和角色列表的:
{% for person in site.people %}
Person {{person.name}}
{% for project in site.projects%}
{% assign person_project = project.participants | where:"name",person.name | first %}
Project: {{project.name}}
Role: {{person_project.role}}
{% endfor %}
{% endfor %}
然后输出如下:
Person julia
Project: Important Project
Role: owner
然后您可以根据需要改进输出,例如使用 table:
{% for person in site.people %}
<table>
<caption>{{person.name}} projects</caption>
<tr>
<th>Project</th>
<th>Role</th>
</tr>
{% for project in site.projects%}
{% assign person_project = project.participants | where:"name",person.name | first %}
<tr>
<td>{{project.name}}</td>
<td>{{person_project.role}}</td>
</tr>
{% endfor %}
</table>
{% endfor %}
输出:
julia projects
Project Role
Important Project owner
我想你的参与者项目看起来像这样:
---
short: julia
firstname: Julia
lastname: Last
layout: participant
---
Content
在您的参与者布局中,您可以:
<h2>Participant : {{ page.firstname }} {{ page.lastname }}</h2>
{{ content }}
<h2>Projects :</h2>
<ul>
{% for project in site.projects %}
{% for participant in project.participants %}
{% if participant.name == page.short %}
<li>{{ participant.role }} in <a href="{{ site.baseurl }}{{ project.url }}">{{ project.name }}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
参加者
我有一个项目集。每个项目的一部分是参与该项目的人员列表:
---
layout: project
name: Important Project
participants:
- name: julia
role: owner
- name: paul
role: manager
- name: chris
role: implementer
---
这些人中的每个人自己都在一个集合中,并且有一个页面列出了他们的详细信息。我想包括他们一直在从事的项目以及他们的角色。这是我的最大努力,但没有用:
{% for project in site.projects %}
{% if project.participants['name'] == {{ page.name }} %}
<p>{{ project.name }} - {{ project.participants['role'] }}</p>
{% endif %}
{% endfor %}
欢迎提出任何建议。
假设这个结构:
# _config.yml
collections:
- people
- projects
然后目录结构如下:
_projects/project1.md
_people/person1.md
_people/person2.md
和person1.mdfront-matter喜欢:
---
name: julia
---
还有上面front-matter你提供的,这是如何显示每个人的项目和角色列表的:
{% for person in site.people %}
Person {{person.name}}
{% for project in site.projects%}
{% assign person_project = project.participants | where:"name",person.name | first %}
Project: {{project.name}}
Role: {{person_project.role}}
{% endfor %}
{% endfor %}
然后输出如下:
Person julia
Project: Important Project
Role: owner
然后您可以根据需要改进输出,例如使用 table:
{% for person in site.people %}
<table>
<caption>{{person.name}} projects</caption>
<tr>
<th>Project</th>
<th>Role</th>
</tr>
{% for project in site.projects%}
{% assign person_project = project.participants | where:"name",person.name | first %}
<tr>
<td>{{project.name}}</td>
<td>{{person_project.role}}</td>
</tr>
{% endfor %}
</table>
{% endfor %}
输出:
julia projects
Project Role
Important Project owner
我想你的参与者项目看起来像这样:
---
short: julia
firstname: Julia
lastname: Last
layout: participant
---
Content
在您的参与者布局中,您可以:
<h2>Participant : {{ page.firstname }} {{ page.lastname }}</h2>
{{ content }}
<h2>Projects :</h2>
<ul>
{% for project in site.projects %}
{% for participant in project.participants %}
{% if participant.name == page.short %}
<li>{{ participant.role }} in <a href="{{ site.baseurl }}{{ project.url }}">{{ project.name }}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
参加者