Smarty template for generating cascaded UL based menu

So far, I’ve been happy how this template behaves when I pass a parent/child links into it.

< {$parent_tag|default:'ul'}{if $menu_id} id="{$menu_id}"{/if}{if $parent_class} class="{$parent_class}"{/if}>{* ul tag opens here *}
{foreach from=$links item=link}
  {if $link.class_active && $link.href == $current_uri}
    {if $link.class}
      {assign var=class value="`$link.class` `$link.class_active`"}
    {else}
      {assign var=class value="`$link.class_active`"}
    {/if}
  {else}
    {assign var=class value="`$link.class`"}
  {/if}
  < {$child_tag|default:'li'}{if $class} class="{$class}"{/if}{if $link.id} id="link_{$link.id}"{/if}>
    {$link.text}
  {if $link.children}
    {include file="links.html" links=$link.children parent_class=""}
  {/if}
{/foreach}
< /{$parent_tag|default:'ul'}>

Does something like this when rendered


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>