How do you template an IF statement to avoid an error if an image is not assigned Here is my templating...

      {% if entry.programImage %}
        &lt;img src="{{ entry.programImage.one().getUrl() }}" alt=""/&gt;
      {% endif %}


The field programImage is NOT required.  

The image does display for entries that have it.
It throws an ERROR for those that do not.  

The ERROR message is as follows.

Impossible to invoke a method ("getUrl") on a null variable.


What am I missing?

Thanks
You're close...

{% set programImage = entry.programImage.one() %}
{% if programImage %}
    &lt;img src="{{ programImage.getUrl() }}" alt=""/&gt;
{% endif %}


You get the the asset model (or null), then check if you actually have it, then finally use it.

It's essentially the same in Craft 2.