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

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

<p>Your code could look like:</p>

<p><code>for cat in craft.categories.group('productCategories').descendantOf(category.id)</code></p>

CC BY-SA 3.0
2015-08-14T13:39:46.133Z
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!
Mark Gifford
CC BY-SA 3.0
2015-08-14T13:19:21.097Z
2015-08-14T13:19:21.097Z
Alec Ritson
<p>When you are on a category page you can simply use the category variable just like you would use the entry variable...</p>

<pre><code>{{ category.id }}
</code></pre>

CC BY-SA 3.0
2015-08-14T14:14:48.133Z
2015-08-14T14:14:48.133Z
j00lz
<p>I haven't used categories before so maybe I'm looking at this the wrong way.</p>

<p>I currently have a category group named products with the following structure:</p>

<pre><code>Featured
Fruit
----Apple
----Banana
Veg
----Turnip
</code></pre>

<p>I know I can do the following to show just the subcategories of fruit:</p>

<pre><code>for cat in craft.categories.group('productCategories').descendantOf("fruit ID")
</code></pre>

<p>But how do I get the "fruit ID" when I'm on the on the fruit page?</p>

<pre><code> craft.categories.relatedTo(entry)
</code></pre>

<p>returns all the categories in products but I want just the current category.</p>

<p>Any help greatly appreciated!</p>

CC BY-SA 3.0
2015-08-14T16:05:15.383Z
I hate to be "that guy", but technically a tomato is a fruit. ;)
Brad Bell
CC BY-SA 3.0
2015-08-20T18:37:37.407Z
the craft page on categories is a great way to learn some other elements of categories you might need for success. http://buildwithcraft.com/docs/categories
Matteo
CC BY-SA 3.0
2015-09-30T04:35:21.873Z
@BradBell for president
Anna_MediaGirl
<entries><categories><relations>
Get current entry category
# Get current entry category

(Asked by: username_0 on 2015-08-14)

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:
Featured
Fruit
----Apple
----Banana
Veg
----Turnip

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?
 craft.categories.relatedTo(entry)

returns all the categories in products but I want just the current category.
Any help greatly appreciated!

**Tags:** entries, categories, relations

> **Comments:**
> **username_1**: I hate to be "that guy", but technically a tomato is a fruit. ;)  
> **username_2**: the craft page on categories is a great way to learn some other elements of categories you might need for success. http://buildwithcraft.com/docs/categories  
> **username_3**: @BradBell for president  

---

## 2 answers

### Answer by username_4 on 2015-08-14. Score: 2 | Accepted answer

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)`

> **Comments:**
> **username_0**: 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!  

---

### Answer by username_5 on 2015-08-14. Score: 1

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


---

