Answers.Body: <p>Required a different operator </p>
  
  <pre><code>{% set affiliateLink = relatedEntry.offerLink ?? relatedEntry.affiliateUrl %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-04T20:09:38.617Z
Answers.LastActivityDate: 2018-06-04T20:09:38.617Z
Answers.UserDisplayName: JMKelley
Body: <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>
  
Tags: <templating><entries>
Title: Set Variable if Current Field is Empty
ThreadText: # 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 %}
            <div class="utility-vertical-align">
              <a href="{{ affiliateLink }}" target="_blank" class="btn btn-voucher btn-lg btn-block">Get This Offer<i class="material-icons float-sm-right">chevron_right</i></a>
            </div>
          {% else %}
            <div class="utility-vertical-align">
              <pre>
                  window.aPopunder = [
                      ['{{ relatedEntry.offerLink }}']
                  ];
              </pre>
              <a href="{{ relatedEntry.url }}" target="_blank" class="btn btn-voucher btn-lg btn-block" onclick="$.popunder(this);">Reveal Code & Visit<i class="material-icons">chevron_right</i></a>
            </div>
          {% 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 %}
  
  ```
  
  
  ---
  
  