# How to access the subcategories in Smarty template?

**URL:** <https://forum.shopware.com/t/how-to-access-the-subcategories-in-smarty-template/40864>\
**Category:** Themes & Design\
**Created:** [26. Oktober 2016 um 21:17 UTC](https://forum.shopware.com/t/how-to-access-the-subcategories-in-smarty-template/40864 "2016-10-26T21:17:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![despot82](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@despot82](https://forum.shopware.com/u/despot82)\
**Post date:** [26. Oktober 2016 um 21:17 UTC](https://forum.shopware.com/t/how-to-access-the-subcategories-in-smarty-template/40864/1 "2016-10-26T21:17:01Z")

</div>

I want to reimplement the main menu by changing one of the built-in Shopware’s .tpl files. I need to get the subcategries of each main category and so on (subcategories of a subcategory, if exists, etc.) How can I do this? I know that I have immediate access to $sMainCategories in smarty, but when I try to access subcategories by:  
{foreach $sMainCategory as $mc}

{foreach $mc.subcategories as $sc}

{$sc}

{/foreach}

{/foreach}

I don’t get anything, and when I output the variable {$mc.subcategories} , by using {$mc.subcategories@print\_r} ,I get an empty array. I know that there are subcategories in that maincategory, and all categories and subcategories are active. Why can’t I access subcategories of a category in smarty template?

&nbsp;

---

<div class="post-metadata">

**Author:** ![steinsoftware](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@steinsoftware](https://forum.shopware.com/u/steinsoftware)\
**Post date:** [31. Oktober 2016 um 14:37 UTC](https://forum.shopware.com/t/how-to-access-the-subcategories-in-smarty-template/40864/2 "2016-10-31T14:37:57Z")

</div>

It isn’t called $sMainCategory but $sMainCategories.

---

<div class="post-metadata">

**Author:** ![rreimche](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rreimche](https://forum.shopware.com/u/rreimche)\
**Post date:** [28. August 2020 um 11:53 UTC](https://forum.shopware.com/t/how-to-access-the-subcategories-in-smarty-template/40864/3 "2020-08-28T11:53:12Z")

</div>

> [@steinsoftware schrieb:](https://forum.shopware.com/profile/17116/steinsoftware "steinsoftware")
> 
> It isn’t called $sMainCategory but $sMainCategories.

It seems that $sMainCategories as well as $sCategories lack all the subcategories except the one of the current $sMainCategory and of the categories that are on direct path to the „tail“-Category of the product. However, if we activate the Advanced Menu plugin and configure it appropriately (the number of levels of subcategories to show), we get $sAdvancedMenu with all the required information.
