I'm attempting to pull out a list of categories starting with certain letter(s).

What I've come up with so far seems a little excessive and I'm wondering if I've missed something obvious.

Can it all be done with just the 'craft.categories...' line?

{% set allCats = craft.categories.group('listingCategories').order('title').limit(null).find() %}
{% set allCatsByLetter = allCats|group('title | first') %}

{% for letter, allCats in allCatsByLetter if letter == "A" %}
        {% for cat in allCats %}
            <li>{{ cat.title }}</li>
        {% endfor %}
{% endfor %}
  • I like this approach better then mine using search, Steve! – carlcs Nov 17 '14 at 17:41

If you don't mind using the search parameter you could add it like this:

{% set beer = 'a' %}
{% set allCats = craft.categories.search('title:' ~ beer ~ '*').limit(null) %}
  • Upvoted for your use of 'beer'. – Steve Abraham Nov 17 '14 at 17:57

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.