Search code examples
smartyshopware

Access sub sub category, Shopware, Smarty


trying to solve issue with sub sub category access in Shopware with smarty, but not sure at all how to do it. Maybe someone knows.

<!-- THIS WORKS -->

{if $Category.sub}
  {foreach $Category.sub as $sub}
    <li>
      <a href="#">
        <span itemprop="name">{$sub.name}</span>
      </a>
    </li>
  {/foreach}
{/if}

<!-- THIS DOESN'T WORK -->
{if $Category.sub.sub}
  {foreach $Category.sub.sub as $subsub}
    <li>
      <a href="#">
        <span itemprop="name">{$subsub.name}</span>
      </a>
    </li>
  {/foreach}
{/if}


Solution

  • please check example above:

    {foreach $Category.sub as $categoryItem}
        {foreach $categoryItem.sub as $subsub}
            <li>
                <a href="#">
                    <span itemprop="name">{$subsub.name}</span>
                </a>
            </li>
        {/foreach}
    {/foreach}
    

    Advanced example:

    {foreach $Category.sub as $number => $categoryItem}
        {if $categoryItem.childrenCount}
            <ul id="submenu-{$number}" {if $categoryItem.flag}class="is--active"{/if}>
                {if $categoryItem.cmsHeadline}
                    <li class="menu--list-item item--level-1">
                        <span class="menu--list-item-title">{$categoryItem.cmsHeadline}</span>
                    </li>
                {/if}
                {foreach $categoryItem.sub as $subcategory}
                    {if $subcategory.hideTop}
                        {continue}
                    {/if}
    
                    {$categoryLink = $subcategory.link}
                    {if $subcategory.external}
                        {$categoryLink = $subcategory.external}
                    {/if}
    
                    <li class="menu--list-item item--level-1{if $subcategory.flag} item--is-active{/if}">
                        <a href="{$categoryLink|escapeHtml}" class="menu--list-item-link" title="{$subcategory.name|escape}">{$subcategory.name}</a>
                    </li>
                {/foreach}
            </ul>
        {/if}
    {/foreach}