Home > Software design >  Get list of Jekyll attribute to iterate through
Get list of Jekyll attribute to iterate through

Time:12-24

I am currently trying to build a website that will display team members using Jekyll and was wondering if there was an elegant way to make iterate and group people from specific groups.

So for reference point what I have is a md file collection that works containing the

name: Person Name
team: Team
image: pnglinkhere

And I was wondering if it is possible to iterate programmatically with something like this?

{% for team in site.people | [some how get list of unique team attributes] %}
<h5>{{ team }}</h5>
{% for people in site.people %}
{% if people.team = team % }
<div>Show Person</div>
{% endif %}
{% endfor %}
{% endfor %}

Any solution that doesn't involve folder reorganization would be beneficial and appreciated. I'm mainly looking for a programmatic way so it makes changes easier and so if a new is added I don't have to copy-paste for the new team.

Thank you

CodePudding user response:

Your idea looks ok. Check out group_by and where filters described at https://jekyllrb.com/docs/liquid/filters/.

Whatever filter or condition you use, you may need to assign your people to a variable.

Group By

Group an array's items by a given property.

{{ site.members | group_by:"graduation_year" }}

[{"name"=>"2013", "items"=>[...]}, {"name"=>"2014", "items"=>[...]}]

{% assign people_grouped_by_xyz = site.people | group_by: your_attribute %}
{% for team in people_grouped_by_xyz %}
...

Where

Select all the objects in an array where the key has the given value.

{{ site.members | where:"graduation_year","2014" }}

{% assign people_grouped_by_xyz = site.people | where: "your_attribute","value" %}
{% for team in people_grouped_by_xyz %}
...

CodePudding user response:

{% assign people_grouped_by_xyz = site.people | where: "your_attribute","value" %} {% for team in people_grouped_by_xyz %} ...

  • Related