Conditional for loop on index

Hello, someone can inform if is possoble to make a conditional loop that depend if the attribute is not nil?

for exemple:

{% for boat in %}

{{ }}

{% endfor %}
name: Azimut
sell: yes

if the sell is not nil, show the boats

An if statement should work for boolean, nil, and undefined values:

{% if boat.sell %}
{{ }}
{% endif %}

@chuckhoupt thank you very much that’s it worked smoothly :grinning:

One more option is to first assign the variable and use a where clause. This is super useful because you don’t need to do a for loop with another if clause inside it.

For example, I created a ./_data/boats.yml file (the ‘.’ represents the top-level of the Jekyll site’s folder structure):

    - title:
      name: Azimut
      sell: "Yes"
    - title:
      name: Azimut2

Note: The “Yes” is best to be in quotes due to what I think is a problem with Jekyll’s where filter when dealing with truthy data.

And here is the simplified code:

{%- assign boats = | where: "sell", "Yes" -%}
{%- for boat in boats -%}
    <p>Name: {{ }}</p>
{%- endfor -%}```

The output is:

Name: Azimut

YAML is tricky because yes/no and true/false are booleans, but "Yes", yea, nope, etc. are strings, which are always truthy.

If one uses “true” booleans for the sell field, then the where_exp filter can be used to filter like this (the test is equivalent to {% if boat.sell %}):

{% assign boats = | where_exp: "boat", "boat.sell" %}