conditional based on existence of YAML key

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, and have tried using:

  • {% if == blank %} {{ "no phone number listed" }} {% endif %}
  • {% if == false %} {{ "no phone number listed" }} {% endif %}
  • {% if == 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?

I don’t think you should have curly brackets around this. I think is blank is the correct test.