2

I'm using a matrix field to allow the author to add products they can link to category pages, but my code:

{% for block in entry.transformerProductNavigation %}
 <a href="{{ block.transformer.one.url }}">{{ block.transformer.one.title }}</a>
{% endfor %}

outputs the parent category, can I somehow display the nested category – as you would if it was an entry field and nested entries?

| improve this question | | | | |
  • With an entry field you can access the nested entries so not sure what the difference is here – user2569 Nov 20 '19 at 16:54
2

This solves my problem:

{% for block in entry.transformerProductNavigation %}
{% set chosenCategory = block.transformer.last() %}

      {# set a variable – chosenCategory to the 'last' category ensuring any nested categories are accessible   #}
      <a href="{{ chosenCategory.slug }}">{{ chosenCategory.title }}</a>

{% endfor %}

Thanks to this answer: How to fetch only selected child category?.

| improve this answer | | | | |

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.