I'm really struggling to display entries of a category, based on the segment. In other words, I have 1 category template, so the category needs to be determined dynamically (*we still do this by segment, right?? or is that not the best practice?)

I was trying something like this, but I can't seem to get it right:

{% for category in craft.categories.group('typeOfPack').find() %}
     {% set active = (
        craft.request.Segment(2) == category.slug
     ) %}

    {% for entry in entry.typeOfPack.search('active').find()  %}
        <h3>{{ entry.title }}</h3>
    {% endfor %}

{% endfor %}

Apologies if this offensively bad. As I try to get my head around Twig, I'm wondering if there are some high level errors, for instance: 1. Does the {% for entry... %} need to be inside the {%for category... %}? Do I even need to do the {% for category...%} stuff if I'm just needing entries, or is the ".search(...)" sufficient?

Thank you so much.

Big Mike

1 Answer 1


How do I list the entries related to a category? article on the Craft site should get you headed in the right direction.

You can fetch the entries related to a given category with a little help from craft.entries and the relatedTo param.

{# Fetch all of the entries related to this category #}
{% set entries = craft.entries.relatedTo(category) %}

{# Output them #}
{% for entry in entries %}
    <a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}

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.