Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming question about loops with Jekyll #29

Open
NickvashKani opened this issue Jan 21, 2023 · 1 comment
Open

Programming question about loops with Jekyll #29

NickvashKani opened this issue Jan 21, 2023 · 1 comment

Comments

@NickvashKani
Copy link
Contributor

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
Copy link
Member

sampsyo commented Jan 21, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants