2

Having a bear of a time doing something which seems like it should be quite simple. I'm trying to display the category group name in my templates, using the handle and can't quite get it. I've explored the docs but haven't found much help there.

I've tried:

{{ caseStudiesCategories }}

Error: Variable "caseStudiesCategories" does not exist

As well as:

{%  set catName = craft.categories.group('caseStudiesCategories') %}
{{ catName }}

Error: Object of class Craft\ElementCriteriaModel could not be converted to string

Any thoughts or ideas?

Thanks.

2

You're close! It's slightly counterintuitive but group is a property of a category. So you need to grab the group from an actual category. This would work:

{% set catName  = craft.categories.group('caseStudiesCategories').first.group %}

Basically you're getting the first category in the group and grabbing the group name (you could also use [0] instead of .first).

If your entry has a category field, you can access the group name in a similar fashion:

{% set catName = entry.yourCategoryField.first().group %}
  • No problem! Assets, relations, and entries work more or less the same way so once you get that, everything else is cake. – RitterKnight Nov 4 '15 at 20:03

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.