Page 1 of 1

Bootstrap Dropdown Menu using CMSMS Simplex_menu

Posted: Wed Jun 29, 2016 9:18 am
by naturelab
I am trying to use the Simplex_menu to output a Bootstrap 3 Dropdown Menu, like this :-

https://getbootstrap.com/examples/navbar/#

At the moment, my output is this :-

Code: Select all

<li class=' active dropdown' aria-haspopup='true'>
<a class='' href='http://mysite.com/parent/'>Parent</a>
<ul class="dropdown-menu">
<li class=''><a class='' href='http://mysite.com/parent/child'>Child</a></li>
<li class=''><a class='' href='http://mysite.com/parent/child'>Child</a></li>
What I actually want is this ( as shown in the url example - https://getbootstrap.com/examples/navbar/# )

Code: Select all

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a class='' href='http://mysite.com/parent/'>Parent</a></li>
<li role="separator" class="divider"></li>
<li class=''><a class='' href='http://mysite.com/parent/child'>Child</a></li>
<li class=''><a class='' href='http://mysite.com/parent/child'>Child</a></li>
The nav template I am using is here :-

Code: Select all

{strip}

{function do_class}
    {if count($classes) > 0} class='{implode(' ',$classes)}'{/if}
{/function}

{function name='Simplex_menu' depth='1'}
    {"\n"}<ul{$main_id}{if isset($ul_class) && $ul_class != ''} class="{$ul_class}"{/if}>{"\n"}
        {$main_id = ''}
        {$ul_class = 'dropdown-menu'}
        {foreach $data as $node}
            {* setup classes for the anchor and list item *}
            {$list_class = ['']}
           {$href_class = ['']}
           {$parent_indicator = ''}
            {$aria_support = ''}

            {if $node->current || $node->parent}
                {* this is the current page *}
                {$list_class[] = 'active'}
                {$href_class[] = 'dropdown-toggle'}
            {/if}

            {if $node->children_exist}
                {$list_class[] = 'dropdown'}
                {$aria_support = ' aria-haspopup=\'true\''}
                {$parent_indicator = ''}
                 {$href_class = 'dropdown-toggle'}

            {/if}

            {* build the menu item node *}
            {if $node->type == 'sectionheader'}
                {$list_class[] = 'sectionheader'}
                <li{do_class classes=$list_class}{$aria_support}><span>{$node->menutext}{$parent_indicator}</span>
                {if isset($node->children)}
                    {"\n"}{Simplex_menu data=$node->children depth=$depth+1}
                {/if}
                </li>{"\n"}
            {else if $node->type == 'separator'}
                {$list_class[] = 'separator'}
                <li{do_class classes=$list_class}'><hr class='separator'/></li>{"\n"}
            {else}
                {* regular item *}
                <li{do_class classes=$list_class}{$aria_support}>
                    <a{do_class classes=$href_class} href='{$node->url}'{if $node->target != ''} target='{$node->target}'{/if}>{$node->menutext}{$parent_indicator}</a>
                    {if isset($node->children)}
                        {Simplex_menu data=$node->children depth=$depth+1}
                    {/if}
                </li>{"\n"}
            {/if}
        {/foreach}
    </ul>{"\n"}
{/function}

{if isset($nodes)}
    {Simplex_menu data=$nodes depth='0' ul_class='nav navbar-nav'}
{/if}

{/strip}
Has anyone done this ? Is it possible ?
Any help greatly appreciated.

Re: Bootstrap Dropdown Menu using CMSMS Simplex_menu

Posted: Wed Jun 29, 2016 11:53 am
by velden