Unexpected output from Twig set variable My entry has a custom field to set a social image for Facebook.

In the entry template, I'm defining the output like so:

{% set social_image = "" %}
  {% for image in entry.metaImage %}
    {% set social_image = image.getUrl() %}
  {% endfor %}


Then in the layout I have this 

&lt;meta property="og:image" content="{% if social_image is defined %}{{ social_image }}{% endif %}" /&gt;


and this works great. However, when that field hasn't been, I want to fallback to a custom field that will always have an image set.

I tried to change the layout to {% if social_image is not null %}{{ social_image }}{% else %}{{ social_image_fallback }}{% endif %} setting social_image_fallback within the entry template of course, but that outputs a null value.

I originally had {% if social_image is defined %} but of course if defined would always evaluate to true.

I'm missing something simple here right?
Try {{ social_image|default(social_image_fallback) }}. I've had good results using Twig's default filter over testing variables, even with multiple fallbacks. (like this).