I haven't used categories before so maybe I'm looking at this the wrong way.

I currently have a category group named products with the following structure:


I know I can do the following to show just the subcategories of fruit:

for cat in craft.categories.group('productCategories').descendantOf("fruit ID")

But how do I get the "fruit ID" when I'm on the on the fruit page?


returns all the categories in products but I want just the current category.

Any help greatly appreciated!

  • 2
    I hate to be "that guy", but technically a tomato is a fruit. ;)
    – Brad Bell
    Aug 14, 2015 at 16:05
  • the craft page on categories is a great way to learn some other elements of categories you might need for success. buildwithcraft.com/docs/categories
    – Matteo
    Aug 20, 2015 at 18:37
  • @BradBell for president
    – Anna_MediaGirl
    Sep 30, 2015 at 4:35

2 Answers 2


I take it you are on the category template as defined in admin/settings/categories/:id.

You should have a model representation of the category assigned to category in the template, so you should be able to get the current category id by simply doing {{ category.id }} in the template.

Your code could look like:

for cat in craft.categories.group('productCategories').descendantOf(category.id)

  • Great, that's the issue, as I said I haven't used categories before so I thought I could use the entry variable but this makes sense as it's a category not an entry! Aug 14, 2015 at 13:39

When you are on a category page you can simply use the category variable just like you would use the entry variable...

{{ category.id }}

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.