I have a section type Structure called How to videos, in which I have field type Entries.

Now, when I select "Products" in the field type 'Entries'. I only want the selected Entries Products to show text "Click here to view". If there is no entry added in entries fields it should not show text "Click here to view".

How can I template the Entries field?


You'll need to do something like this. entry is a How to videos entry.

{% set relatedProducts = entry.productsEntryField.all() %}

{% if relatedProducts|length %}
    {% for product in relatedProducts %}
        <a href="{{ product.url }}">Click here to view</a>
    {% endfor %}
{% endif %}

The Craft docs on Entries Fields has more info.

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.