Checking if items in a yaml file equal one?

{% if item in cover.images == 1 %} doesn’t work. How can I check if there is one item in a list?

Thanks!

Tried that but couldn’t get it to work properly.

The dot-notation form doesn’t work? This assumes cover.images is a list/array:

{% if cover.images.size == 1 %}

This is in the yaml:

images:
  - image: 'static/images/covers/doctor.jpeg'
  - image: 'static/images/covers/hello.jpeg'

Tried that, but didn’t work.

Below is an example using the YAML data (tested and working). Is it possible that cover.images isn’t returning the array you expect? You might check with {{ cover.images | inspect }} to verify its contents.

test.md:

---
images:
  - image: 'static/images/covers/doctor.jpeg'
  - image: 'static/images/covers/hello.jpeg'
---

Size: {{ page.images.size }}

There are
{%- if page.images.size == 1 %} One {% endif %}
{%- if page.images.size == 2 %} Two {% endif %}
images.
1 Like

Worked, thanks so much!