1

I've setup a Matrix field with an entries field and output the value like this:

{% set entry = block.blockLink.first() %}
 {% if entry %}
  <p class="ctaLink"><a href="{{ entry.url }}">Find out more</a></p>
 {% endif %}    

This outputs the value of the entries field OK. However any other Matrix field that follows on from this one fails to display at all. What am I doing wrong? Any advice gratefully received!

2
  • After trial and error I came up with this alternative: ` {% if block.blockLink|length %} <p class="ctaLink"><a href="{{ block.blockLink.first.url }}">Find out more</a></p> {% endif %}`
    – Andrew
    Oct 3 '17 at 11:17
  • I'm not exactly sure I'm following, but would you mind adding what worked for you as an official answer? Might help someone in the future.
    – Brad Bell
    Oct 3 '17 at 18:33
1

My suspicion is that the entry you are defining is confilicting with the entry that Craft gives you as the entry that this template is displaying. Try this, and see if it helps:

{% set blockLinkEntry = block.blockLink.first() %}
{% if blockLinkEntry %}
  <p class="ctaLink"><a href="{{ blockLinkEntry.url }}">Find out more</a></p>
{% endif %}
1
  • I haven't tried this as the solution I used above was working. Thanks for your input.
    – Andrew
    Oct 4 '17 at 9:14
0

After trial and error I came up with this alternative:

{% if block.blockLink|length %}
  <p class="ctaLink"><a href="{{ block.blockLink.first.url }}">Find out more</a</p>
{% endif %}

This worked for me, but I'm not sure if it's the 'correct' method or not.

1
  • Both cases you are avoiding overwriting the entry that Craft has set for you. Either one is correct. Oct 4 '17 at 14:56

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.