Shopware: Define custom variables

With the following code-snippet you can define your own variables in your template-file. The only thing you need, is the Smarty-Tag {assign}.

In this example I want to save in my custom variable „hasSubmenu“ if the current category has subcategories or not.

{foreach $sMainCategories as $sCategory}
    {if !$sCategory.hideTop}
        {if $sCategory.flag}
            {if $sCategory.sub}
                {assign var="hasSubmenu" value="true"}
            {else}
                {assign var="hasSubmenu" value="false"}
            {/if}
        {/if}
    {/if}
{/foreach}