# conditional based on existence of YAML key

**URL:** <https://talk.jekyllrb.com/t/conditional-based-on-existence-of-yaml-key/8783>\
**Category:** Help\
**Created:** [December 26, 2023, 9:09pm UTC](https://talk.jekyllrb.com/t/conditional-based-on-existence-of-yaml-key/8783 "2023-12-26T21:09:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccw34](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@ccw34](https://talk.jekyllrb.com/u/ccw34)\
**Post date:** [December 26, 2023, 9:09pm UTC](https://talk.jekyllrb.com/t/conditional-based-on-existence-of-yaml-key/8783/1 "2023-12-26T21:09:00Z")

</div>

I’m trying to generate output based on whether a YAML key exists. Given a file in `_data` called `users.yml`:

```yaml
 - 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?

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [December 27, 2023, 12:38am UTC](https://talk.jekyllrb.com/t/conditional-based-on-existence-of-yaml-key/8783/2 "2023-12-27T00:38:58Z")

</div>

> [@ccw34](#):
>
> {{ “no phone number listed” }}

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