I am trying to create a category template that shows all entries to show relating to the categories.

At the minute the cats are

  1. Industry
  2. Chemical
  3. Medical

1 Answer 1


Personally I would set the category select field outside of the matrix block but that's up to you. The problem you are running in to at the moment is you are not looping over the matrix field.

{% for entry in craft.entries.section('job') %}
    {% for block in entry.matrixFieldName if block.type == 'job' %}
        {% for category in block.category %}
        {% endfor %}
        <a href="{{ entry.url }}">{{ block.title }}</a><br>
    {% endfor %}
{% endfor %}

So what we are doing here in the first loop we dive into the jobs section.

{% for entry in craft.entries.section('job') %}

Once we are inside a job entry we loop over the matrix field containing the "job" block. We only want to display the "job" block (security for when you add more blocks in the future).

{% for block in entry.matrixFieldName if block.type == 'job' %}

Once we get into the matrix field we loop over the selected category field. This way you get access to all the fields inside that category (including the title).

{% for category in block.category %}

Now you have access to all the fields. All the fields you want to use from the jobs entry you can grab by {{ entry.field }}. All the fields inside the matrix block by {{ block.field }}. And everything inside the category by {{ category.field }}.


Correct me if I get you wrong.

I guess you have a field that connects an entry to a category but what you could try is something like this:

{% for entry in craft.entries.section('jobs') %}
    {% for category in entry.CATEGORYFIELD %}
    {% endfor %}
     <a href="{{entry.url}}">{{entry.title}}</a><br>
{% endfor %}

This is if the order doesn't matter.

  • I have a matrix field which holds the category for the entry. The user then sets this when creating the entry. The matrix block type is called jobs and the field is called category. Is this what you mean?
    – FEDev
    Jun 13, 2017 at 13:36
  • @DannyT So you dont actually make another entry. You just add another matrix block and connect the matrix blocks to a category instead of an entire entry. If that's the case you I can setup an better answer for you. Do you minde posting a picture of the page inside the CMS? Jun 13, 2017 at 14:21
  • Not exactly. I have a section set up called "jobs" and a field which is a matrix called "job" everytime i want a new job i create an entry inside the jobs channel and add the matrix block job inside that entry. I hope that makes sense.
    – FEDev
    Jun 13, 2017 at 14:24
  • @DannyT I've updated the answer Jun 13, 2017 at 15:06
  • 1
    @DannyT that’s exactly the reason why you’d be better off assigning the categories field directly to the entry.
    – carlcs
    Jun 13, 2017 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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