{strip}
{* Coerce and render safely; recurse through .pages *}

{assign var=menu value=$menuList|default:[]}

{function name=render_menu items=[] level=0}
  {assign var=list value=$items|default:[]}
  {if $list|@count}
    <ul{if $level>0} class="submenu level-{$level}"{/if}>
      {foreach $list as $item}
        {assign var=href value=$item.URL|default:''}
        {if $href|@preg_match:'/^https?:\/\//' }
          {assign var=base value=''}
        {else}
          {assign var=base value=$smarty.const.SITE_URL}
        {/if}
        <li>
          <a href="{$base}{$href}">{l}{$item.LABEL|default:''}{/l}</a>
          {if $item.pages|default:[]|@count}
            {call name=render_menu items=$item.pages level=$level+1}
          {/if}
        </li>
      {/foreach}
    </ul>
  {/if}
{/function}

{call name=render_menu items=$menu level=0}
{/strip}
