Jump to content

MarkupSimpleNavigation Menu Showing Children of Current Page - How?


Recommended Posts

Posted

I know this must be simple, but I'm having a heck of a time trying to figure this out.

I want to add a menu into a page that shows the children of that page. In other words, this page is just a container page of the sub pages and I want to display those sub pages as a menu inside the current page.

Please Help

Posted

I guess this was quite easy to do w/out MarkupSimpleNavigation...

<?php
echo "<ul>";
foreach($page->children as $child){
  echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
}
echo "</ul>";
?>
 
Posted

If you read the manual you'll find that the last argument you can specify the root parent page... that would be simply the current $page.

Posted

Soma, I was trying to do that but couldn't figure out exactly how - I'm still pretty new at this :(

For example, I tried this with no success:

<?php $treeMenu = $modules->get("MarkupSimpleNavigation");
$rootPage = $page;
        $options = array(
    'parent_class' => 'parent',
    'current_class' => 'current-menu-item',
    'has_children_class' => '',
    'levels' => false,
    'levels_prefix' => '',
    'max_levels' => 2,
    'firstlast' => false,
    'collapsed' => false,
    'show_root' => false,
    'selector' => '',
    'selector_field' => 'nav_selector',
    'outer_tpl' => '<ul class="dl-menu">||</ul>',
    'inner_tpl' => '<ul class="dl-submenu">||</ul>',
    'list_tpl' => '<li%s>||</li>',
    'list_field_class' => '',
    'item_tpl' => '<a href="{url}">{title}</a>',
    'item_current_tpl' => '<a href="{url}">{title}</a>',
    'xtemplates' => '',
    'xitem_tpl' => '<a href="/{url}">{title}</a>',
    'xitem_current_tpl' => '<a href="/{url}">{title}</a>'
    );
    echo $treeMenu->render($options,$rootPage);
    ?>
 
Posted

You have the rootPage as second argument. Insert null as second, this is to overwrite current page active.

Posted

Just to make it complete with a working example (now at desktop):

$treeMenu = $modules->get("MarkupSimpleNavigation");
$rootPage = $page;

$options = array(
    'current_class' => 'current-menu-item',
    'has_children_class' => '',
    'max_levels' => 2,
    'outer_tpl' => '<ul class="dl-menu">||</ul>',
    'inner_tpl' => '<ul class="dl-submenu">||</ul>',
    'item_tpl' => '<a href="{url}">{title}</a>',
    'item_current_tpl' => '<a href="{url}">{title}</a>',
);

echo $treeMenu->render($options, null, $rootPage);
Posted

@Soma: feature request :-)

Remove Indentation, not rendering tabs newlines & other unnecessary white-space characters.

Lot's of time, ill remove them with regex, but hey, i'm lazy...

Posted

@Soma: feature request :-)

Remove Indentation, not rendering tabs newlines & other unnecessary white-space characters.

Lot's of time, ill remove them with regex, but hey, i'm lazy...

Not the right thread but I hear you.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...