Set Variable if Current Field is Empty I'm trying to set a variable within my templates which does the following:


  If this field is empty then use another field instead.


I have 2x Fields called affiliateUrl and offerLink, if offerLink is empty, then use the affiliateUrl instead.

The current code I'm running is this:

{% set affiliateLink = relatedEntry.offerLink ? relatedEntry.affiliateLink : relatedEntry.affiliateUrl %}


Error Code:


  Calling unknown method: craft\elements\Entry::affiliateLink()


The rest of the code is below:

        {% set affiliateLink = relatedEntry.offerLink ? relatedEntry.affiliateLink : relatedEntry.affiliateUrl %}


        {% if relatedEntry.offerCode is empty %}
          &lt;div class="utility-vertical-align"&gt;
            &lt;a href="{{ affiliateLink }}" target="_blank" class="btn btn-voucher btn-lg btn-block"&gt;Get This Offer&lt;i class="material-icons float-sm-right"&gt;chevron_right&lt;/i&gt;&lt;/a&gt;
          &lt;/div&gt;
        {% else %}
          &lt;div class="utility-vertical-align"&gt;
            &lt;pre&gt;
                window.aPopunder = [
                    ['{{ relatedEntry.offerLink }}']
                ];
            &lt;/pre&gt;
            &lt;a href="{{ relatedEntry.url }}" target="_blank" class="btn btn-voucher btn-lg btn-block" onclick="$.popunder(this);"&gt;Reveal Code &amp; Visit&lt;i class="material-icons"&gt;chevron_right&lt;/i&gt;&lt;/a&gt;
          &lt;/div&gt;
        {% endif %}
Required a different operator 

{% set affiliateLink = relatedEntry.offerLink ?? relatedEntry.affiliateUrl %}