Reputation: 606
So I want to implement a for loop in Jekyll with a variable to the _data file, kinda like
{% for person in site.data.{{ page.base }}.persons %}
{{ person.name }}
{% endfor %}
In this case {{ page.base }}
is set to build
, I also need it to be set to program
, manage
, and web
. And all these variables are defined in my build.md
or program.md
and so on.
I have my for loop in the _layouts
folder. I've tried using the [page.base]
method but it's not working. Here is my code:
---
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>
This is my build.md
YAML, (I think it's 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.
---
Upvotes: 1
Views: 379
Reputation: 12582
This can be simpler. This could be your persons.yml:
- name: Tom
teams:
- build
- program
- name: Violet
teams:
- program
This could be your Liquid:
{% for person in site.data.persons %}
{% if person.teams contains page.base %}
{{ person.name }}
{% endif %}
{% endfor %}
Upvotes: 1