1

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 %}
1

Required a different operator

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.