Skip to content

Instantly share code, notes, and snippets.

@taion809
Created September 11, 2013 08:40
Show Gist options
  • Save taion809/6520897 to your computer and use it in GitHub Desktop.
Save taion809/6520897 to your computer and use it in GitHub Desktop.
flat nested set to bootstrap 2.3 nested menu
<?php
$current_depth = 1;
$html = '';
foreach($menu as $key => $value)
{
if(isset($menu[$key+1]) && $menu[$key+1]->DEPTH > $current_depth)
{
if($current_depth > 1)
{
$html .= "<li class='dropdown-submenu'>" . "\n";
$html .= '<a tabindex="-1" href="#">'.$value->title.' </a>' . "\n";
}
else
{
$html .= "<li class='dropdown'>" . "\n";
$html .= '<a class="dropdown-toggle" data-toggle="dropdown" href="#">'.$value->title.' <b class="caret"></b></a>' . "\n";
}
$html .= '<ul class="dropdown-menu">' . "\n";
++$current_depth;
continue;
}
elseif($value->DEPTH < $current_depth)
{
$html .= '</ul>' . "\n";
$html .= "</li>" . "\n";
--$current_depth;
}
if($value->type_title == 'link')
{
$html .= '<li><a href="'.$value->url.'">'.$value->title.'</a></li>' . "\n";
}
elseif($value->type_title == 'separator')
{
$html .= '<li class="divider"></li>' . "\n";
}
}
echo $html;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment