Cannot skip CSV rows with if condition

Suppose I have a CSV table in /_data/people.csv:

name,surname,meeting
Bob,Marley,
Billy,Joe,2021-03-12
Charles,Dickens

If I want to skip entries which contain the “meeting” field, and enter only the ones which have it empty, I would write:

<ul>
    {% for person in site.data.people %}
        {% if person.meeting == '' %}
            <li>{{ person.name }}</li>
        {% endif %}
    {% endfor %}
</ul>

No entry shows up, I should see Bob and Charles, instead.

It does not work even in this way:

<ul>
    {% for person in site.data.people %}
        {% unless person.meeting %}
            <li>{{ person.name }}</li>
        {% endunless %}
    {% endfor %}
</ul>

or this way:

<ul>
    {% for person in site.data.people %}
        {% if person.meeting %}
            <li>{{ person.name }}</li>
        {% endif %}
    {% endfor %}
</ul>

or this way:

<ul>
    {% for person in site.data.people %}
        {% if person.meeting == nil %}
            <li>{{ person.name }}</li>
        {% endif %}
    {% endfor %}
</ul>

What can I do?

Thank you very much!

Errata corrige: even after removing the {% if %} condition, the for loop does not work.

Why is that happening? I cannot get my head around it.

Please see the problem in the original source files:

Thank you very much again?

I believe the name of the file is missing a letter ‘c’:
acounts.csv => accounts.csv

1 Like

You are right. I am so dumb. Sorry for creating the whole thread for nothing!

Thanks a lot!
Best,
T

It’s all good. Thanks for the well formed question and the detail. Made it easy to spot. Sometimes is just takes a second set of eyes :slight_smile:

This is just a side note, but you might want to consider using YML, JSON, or XML as your data source since CSV is a little more difficult to handle and formatting issues in CSV are quite common.

In case you are new to working with data in Jekyll, here is an overview video I created: