I’m trying to generate output based on whether a YAML key exists. Given a file in _data
called users.yml
:
- name: Paul
phone: 1234
- name: John
- name: George
- name: Ringo
phone: 4567
I loop through the file (using for user in site.data.users
, and have tried using:
{% if user.phone == blank %} {{ "no phone number listed" }} {% endif %}
{% if user.phone == false %} {{ "no phone number listed" }} {% endif %}
{% if user.phone == empty %} {{ "no phone number listed" }} {% endif %}
but none of these print “no phone number listed” for the 2 entries without a phone number. Is there a way to do this, or would I need to explicitly include an empty string as the value for phone
for those users that don’t have one?