Twig help: to test for YAML variable in META file

I cant figure out how to test for the presence of a variable in an yaml meta file.

For example:
imageName.jpg is in the same folder as its meta file imageName.jpg.meta.yaml

The contents of imageName.jpg.meta.yaml are:

title: Image Name
media: acrylic
surface: canvas 36 x 36 inches
style: geometric abstract
portfolio: true
thumbnail: false

I can of course access those variables easily like this <div>{{ }}</div> but if media is not defined in the meta.yaml file, I expected something like this to work (usually using in a for loop):

{% if %}

{{ }}
{% endif %}

But that doesn’t work, it always thinks exists in the meta.yaml file, and when it isn’t defined the output in that

will be a really screwed up tag.

As always, any help is much appreciated.

Your approach works fine for me, just tested. You might want to dump with {{dump(}} to see what’s its value

@ritchiedalto If nothing works, you may try accessing the meta media attribute a bit differently using the get method like

{% if image.get('media') %}
  <div>{{ image.get('media') }}</div>
{% endif %}