for 循环中的 Jekyll 变量到 _data
Jekyll variables inside for loops to _data
所以我想在 Jekyll 中实现一个 for 循环,其中有一个指向 _data 文件的变量,有点像
{% for person in site.data.{{ page.base }}.persons %}
{{ person.name }}
{% endfor %}
本例{{ page.base }}
设置为build
,我还需要设置为program
、manage
、web
。所有这些变量都在我的 build.md
或 program.md
等中定义。
我在 _layouts
文件夹中有我的 for 循环。我试过使用 [page.base]
方法,但它不起作用。这是我的代码:
---
layout: default
---
<div class="column-wrapper">
<div class="grid-x">
<div class="large-6 shrink cell">
<header class="post-header">
<h1 class="post-title">{{ page.title | escape }}</h1>
<div class="no-image-column-wrapper">
<p class="indent">{{ page.description }}</p>
</div>
</header>
</div>
<div class="large-6 shrink cell">
{% include slideshow.html %}
</div>
{% for person in site.data.build.persons %}
<div class="large-6 shrink cell">
<div class="team-image">
<img src="/images/{{ page.base }}/{{ person.name }}.jpg">
</div>
<style type="text/css">
.team-image {
margin-bottom: 4.5rem;
margin-top: 2rem;
max-height: 1rem;
max-width: 16rem;
margin-right: 10rem;
margin-left: 10rem;
padding-bottom: 5rem;
}
</style>
</div>
<div class="large-6 shrink cell">
<div class="no-image-column-wrapper">
<div class="team-bio">
<h3>{{ person.name }}</h3>
<br>
<p>What grade are you in? <strong>{{ person.grade }}</strong></p>
<p>What is your role in robotics? <strong>{{ person.role }}</strong></p>
<p>What is your favorite ice cream? <strong>{{ person.fav }}</strong></p>
<p>What would you like to major in? <strong>{{ person.major }}</strong></p>
<p>What is your biggest pet peeve? <strong>{{ person.pp }}</strong></p>
<p>What is your spirit animal? <strong>{{ person.sa }}</strong></p>
<p>Why are you intrested in robotics? <strong>{{ person.intrest }}</strong></p>
<style type="text/css">
.team-bio {
padding-bottom: 5rem;
}
</style>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
这是我的 build.md
YAML,(我认为是 YAML)。
---
title: Build Team
layout: team
permalink: /teams/build/
base: build
path: images/build/pic
description: The build team is dedicated to building the robot.
---
这可以更简单。这可能是你的 persons.yml:
- name: Tom
teams:
- build
- program
- name: Violet
teams:
- program
这可能是您的 Liquid:
{% for person in site.data.persons %}
{% if person.teams contains page.base %}
{{ person.name }}
{% endif %}
{% endfor %}
所以我想在 Jekyll 中实现一个 for 循环,其中有一个指向 _data 文件的变量,有点像
{% for person in site.data.{{ page.base }}.persons %}
{{ person.name }}
{% endfor %}
本例{{ page.base }}
设置为build
,我还需要设置为program
、manage
、web
。所有这些变量都在我的 build.md
或 program.md
等中定义。
我在 _layouts
文件夹中有我的 for 循环。我试过使用 [page.base]
方法,但它不起作用。这是我的代码:
---
layout: default
---
<div class="column-wrapper">
<div class="grid-x">
<div class="large-6 shrink cell">
<header class="post-header">
<h1 class="post-title">{{ page.title | escape }}</h1>
<div class="no-image-column-wrapper">
<p class="indent">{{ page.description }}</p>
</div>
</header>
</div>
<div class="large-6 shrink cell">
{% include slideshow.html %}
</div>
{% for person in site.data.build.persons %}
<div class="large-6 shrink cell">
<div class="team-image">
<img src="/images/{{ page.base }}/{{ person.name }}.jpg">
</div>
<style type="text/css">
.team-image {
margin-bottom: 4.5rem;
margin-top: 2rem;
max-height: 1rem;
max-width: 16rem;
margin-right: 10rem;
margin-left: 10rem;
padding-bottom: 5rem;
}
</style>
</div>
<div class="large-6 shrink cell">
<div class="no-image-column-wrapper">
<div class="team-bio">
<h3>{{ person.name }}</h3>
<br>
<p>What grade are you in? <strong>{{ person.grade }}</strong></p>
<p>What is your role in robotics? <strong>{{ person.role }}</strong></p>
<p>What is your favorite ice cream? <strong>{{ person.fav }}</strong></p>
<p>What would you like to major in? <strong>{{ person.major }}</strong></p>
<p>What is your biggest pet peeve? <strong>{{ person.pp }}</strong></p>
<p>What is your spirit animal? <strong>{{ person.sa }}</strong></p>
<p>Why are you intrested in robotics? <strong>{{ person.intrest }}</strong></p>
<style type="text/css">
.team-bio {
padding-bottom: 5rem;
}
</style>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
这是我的 build.md
YAML,(我认为是 YAML)。
---
title: Build Team
layout: team
permalink: /teams/build/
base: build
path: images/build/pic
description: The build team is dedicated to building the robot.
---
这可以更简单。这可能是你的 persons.yml:
- name: Tom
teams:
- build
- program
- name: Violet
teams:
- program
这可能是您的 Liquid:
{% for person in site.data.persons %}
{% if person.teams contains page.base %}
{{ person.name }}
{% endif %}
{% endfor %}