uwsampa / research-group-web

a template for research group sites
Other
185 stars 389 forks source link

Programming question about loops with Jekyll #29

Open NickvashKani opened 1 year ago

NickvashKani commented 1 year ago

in role-people.html you loop through the people in the _data/people.yaml file.

I have a Jekyll formatting question. Specifically, the for loop looks like:

{% for item in site.data.people %}
    {% assign person = item[1] %}
           {% if person.role == role.key %}
                   {% include person.html person=person image=include.image %}
           {% endif %}        
{% endfor %}

Why do you need that assign statement? Why can't you use the item variable directly and simply say:

            {% if **item**.role == role.key %}
                    .....

I know my way doesn't work. I just can't figure out why and I was hoping since you guys have more experience, you can tell me why.

Thanks -Nickvash Kani

sampsyo commented 1 year ago

Sorry, I don't recall exactly. The Liquid templating language is, in my opinion, extremely annoying and irregular, so it wouldn't be surprising if weird, inexplicable stuff happened.

In this particular case, however, item[1] is not the same as item. I think it's a pair of names and people, so item[0] would be a name and item[1] is the whole person object. So using item.role wouldn't work; you'd need item[1].role (if Liquid supports that).