2

In a template, I want to show only enabled categories. I can't figure out how to filter the returned categories by only enabled ones, without doing it in the for loop.

This works:

{% for category in craft.categories.level(1) if category.enabled %}
  # only enabled categories
{% endfor %}

but instantiates the disabled categories, even though they won't be used.

2

Something like this should work:

% for category in craft.categories.level(1).enabled(true) %}
    # only enabled categories
{% endfor %}
  • It worked! Thank you. Couldn't find anything in the docs about this and thought I was losing my mind – Chris Jun 6 '17 at 0:20

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.