<p>Required a different operator </p>

<pre><code>{% set affiliateLink = relatedEntry.offerLink ?? relatedEntry.affiliateUrl %}
</code></pre>

CC BY-SA 4.0
2018-06-04T20:09:38.617Z
2018-06-04T20:09:38.617Z
JMKelley
<p>I'm trying to set a variable within my templates which does the following:</p>

<blockquote>
  <p>If this field is empty then use another field instead.</p>
</blockquote>

<p>I have 2x Fields called <code>affiliateUrl</code> and <code>offerLink</code>, if offerLink is empty, then use the affiliateUrl instead.</p>

<p>The current code I'm running is this:</p>

<pre><code>{% set affiliateLink = relatedEntry.offerLink ? relatedEntry.affiliateLink : relatedEntry.affiliateUrl %}
</code></pre>

<p>Error Code:</p>

<blockquote>
  <p>Calling unknown method: craft\elements\Entry::affiliateLink()</p>
</blockquote>

<p>The rest of the code is below:</p>

<pre><code>        {% 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 %}
</code></pre>

<templating><entries>
Set Variable if Current Field is Empty
# Set Variable if Current Field is Empty

(Asked by: username_0 on 2018-06-04)

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 %}
          
            Get This Offerchevron_right
          
        {% else %}
          
            
                window.aPopunder = [
                    ['{{ relatedEntry.offerLink }}']
                ];
            
            Reveal Code & Visitchevron_right
          
        {% endif %}

**Tags:** templating, entries

---

## 1 answers

### Answer by username_0 on 2018-06-04. Score: 1

Required a different operator 
{% set affiliateLink = relatedEntry.offerLink ?? relatedEntry.affiliateUrl %}


---

