Jump to content

MarkupSimpleNavigation


Soma

Recommended Posts

1 hour ago, gregory said:

Hi Soma, I need to create a menu with the centered logo as in the attached example. My idea is to create two different menus. How can it be done?
Thank you

 

multiple-menu.png

I solved by excluding pages. Great! :lol:

 

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi everyone, me again.

I have a problem with my MarkupSimpleNavigation Setup. This is the structure (the important part of it):

- about
	- news (visible in navigation an marked "active" when news-items are selected
		- news-item 1 (not visible in navigation, link will be on the news site)
		- news-item 2  (not visible in navigation, link will be on the news site)
		- news-item 3 (not visible in navigation, link will be on the news site)

From what I found in the forums I have the following php-code for the markup navigation:

<?php
                    
                        /*
                          MarkupSimpleNavigation Example for Bootstrap 2.3.2 Multilevel Navbar
                        */
                        // load MarkupSimpleNavigation module
                        $nav = $modules->get("MarkupSimpleNavigation");
                        /* SETUP HOOKs ------------- */
                        // hook to have custom items markup 
                        $nav->addHookAfter('getTagsString', null, 'customNavItems');
                        function customNavItems(HookEvent $event){
                            $item = $event->arguments('page');
                            // first level items need additional attr
                            if($item->numChildren(true) && count($item->parents) < 2){
                                $title = $item->get("title|name");
                                $event->return = '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $title . ' <b class="caret"></b></a>';
                            }
                            
                            // submenus don't need class and data attribs
                            if($item->numChildren(true) && count($item->parents) > 1){
                                $event->return = '<a href="#" class="active">' . $item->get("title|name") . '</a>';
                            }
                        }
                        // hook to add custom class to li's that have submenu
                        $nav->addHookAfter('getListClass', null, 'customListClass');
                        function customListClass(HookEvent $event){
                            $item = $event->arguments('page');
                            // if current list item has children and is level 2 from root
                            if($item->numChildren(true) && count($item->parents) > 1){
                                $event->return = ' dropdown-submenu'; // adds class to li
                            }
                        }
                        /* Render Navigation Markup ---------------- */
                        $navMarkup = $nav->render(
                            array(
                                'max_levels' => 3,
                                'parent_class' => 'active',
                                'current_class' => 'active',
                                'has_children_class' => 'dropdown', // all li's that have children
                                'outer_tpl' => '<ul class="nav navbar-nav pull-right">||</ul>', 
                                'inner_tpl' => '<ul class="dropdown-menu">||</ul>', 
                                )
                            );

                    echo $navMarkup; ?>

 

I want the navigation link "news" to show the template "news" with links to the "news-items" (that's what I have). "News" should always be "active" when "news" or "news-item" are clicked. What am I missing here?

this is what it looks like so far: http://rolspace.net/hd/energiegossau/uber-uns/news/

Thanks for your help.

Roli

 

 

 

 

Link to comment
Share on other sites

I?m not sure I understand the problem. The "News" entry has a class "active" as it should, but it doesn't show the children as they're hidden dropdown. Seems more like a problem with your html css js.

Link to comment
Share on other sites

35 minutes ago, Soma said:

I?m not sure I understand the problem. The "News" entry has a class "active" as it should, but it doesn't show the children as they're hidden dropdown. Seems more like a problem with your html css js.

aaah! now I see! sometimes, you don't get the most obious things. Thanks Soma!

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

When adding a hook, how do I target the last item in the navigation, regardless of its page id (especially if that page changes)?

What I am trying to do is adding a clickable link that opens a UIKit modal containing the PW search form.  It works just fine if I set the code as a link/button somewhere in the page, but what I want to do is to have it as a menu item. The last item in the menu would be 'Search', and when clicked, will open the modal.

I've tried using a hook (my first time trying hooks), and I got this far using the demo HookEvent:

function myItemString(HookEvent $event){
    $child = $event->arguments('page'); // current rendered child page
    // any logic with $child possible here
    if($child->id == 1016){
        // set the return value of this hook to a custom string
        $event->return .= '<li><a href="#modal-example" title="Search" uk-toggle>Search</a></li>';
    }
}

// setup the hook after on ___getItemString($class, $page) method
$nav->addHookAfter('getItemString', null, 'myItemString');

This adds the 'Search' link after page 1016, but what I want to do is append it to the end of the menu, regardless of what that page id is, keeping it there if the client decides to move page 1016 from the last spot.  Can anyone point me in the right direction? Thanks!

PW 3.0.62
UIKit 3.0
Markup Simple Navigation 1.3.4

Link to comment
Share on other sites

  • 2 weeks later...

Mhh... I think I ran into this problem before and solved it somehow, but can't remember how...

  'item_tpl' => '<a href="{url}">{title} <span>({numChildren})</span></a>',

The {numChildren} counts hidden and unpublished item as well.

Link to comment
Share on other sites

On 8/24/2017 at 8:45 AM, Soma said:

@billjoseph I think what need to do is simply test if it is the last child of its parent.


$parent = $child->parent;
if($parent->children->last === $child) ...

 

If the page is the last "unhidden" page in the admin page tree pages, it works. 

I've got my 404 page and Search Results page as the last two items, both hidden, and I like to keep the tree organized that way, so I modified the logic to this:

$parent = $child->parent;
if($parent->children->last(!hidden) === $child)...

and it seems to work!

Thanks, @Soma for getting me back on the right track with this!!

Link to comment
Share on other sites

@billjoseph

I may be missing something here but why not simply modify the outer_tpl template in $options to include the Search button? Then it would always be the last item in the menu.

'outer_tpl' => '<ul>||<li><a href="#modal-example" title="Search" uk-toggle>Search</a></li></ul>',

 

  • Like 2
Link to comment
Share on other sites

@psy

So, yeah, here's where I throw myself on the mercy of the forums.  I will swear to you up and down that I tried that first and it didn't work, but now, of course, it does.  Maybe I had the <li> outside the </ul>? Maybe I just like to overthink it?

Either way, now I've got two different ways to do it!!

  • Like 1
Link to comment
Share on other sites

13 hours ago, psy said:

@billjoseph

I may be missing something here but why not simply modify the outer_tpl template in $options to include the Search button? Then it would always be the last item in the menu.


'outer_tpl' => '<ul>||<li><a href="#modal-example" title="Search" uk-toggle>Search</a></li></ul>',

 

This is correct and I do that as well, just only works to add something at the end. I assumed he want to add to a end of a pulldown.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I want to create a navigation menu with dropdowns in Bootstrap 4 (ProcessWire 3.0.62 and MarkupSimpleNavigation v1.3.4).
This was possible in Bootstrap 3, but I have yet to see it work with Bootstrap 4.


CODE - FAILS (Bootstrap 4)

    <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
    <?php
        $treemenu = $modules->get("MarkupSimpleNavigation");
        echo $treemenu->render([
            'max_levels' => 2,
            'show_root' => false,
            'parent_class' => 'active',
            'current_class' => 'active',
            'has_children_class' => 'dropdown',
            'outer_tpl' => '<ul class="nav navbar-nav">||</ul>',
            'inner_tpl' => '<ul class="dropdown-menu">||</ul>',
            'list_tpl' => '<li%s>||</li>',
            'list_field_class' => 'nav-item',
            'item_tpl' => '<a href="{url}" class="nav-link">{title}</a>',
            'item_current_tpl' => '<a href="{url}" class="nav-link">{title}</a>',
            'code_formatting' => true,
        ], $page);
    ?>
    </ul>

OBSERVED OUTPUT:

    <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
        <ul class="nav navbar-nav">
            <li class="active dropdown nav-item"><a href="/foo/" class="nav-link">Foo</a>
                <ul class="dropdown-menu">
                    <li class="nav-item"><a href="/foo/bar/" class="nav-link">Bar</a></li>
                    <li class="nav-item"><a href="/foo/baz/" class="nav-link">Baz</a></li>
                </ul>
                </li>
            <li class="dropdown nav-item"><a href="/alfa/" class="nav-link">Alfa</a>
                <ul class="dropdown-menu">
                    <li class="nav-item"><a href="/alfa/beta/" class="nav-link">Beta</a></li>
                </ul>
                </li>
        </ul>
    </ul>

EXPECTED OUTPUT (GOAL):

    <nav class="navbar navbar-expand-md navbar-dark bg-dark">
      <a class="navbar-brand" href="/">EnormiCorp</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

        <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
            <ul class="nav navbar-nav">
                <li class="active dropdown nav-item"><a href="/foo/" class="nav-link">Foo</a>
                    <ul class="dropdown-menu">
                        <li class="nav-item"><a href="/foo/bar/" class="nav-link">Bar</a></li>
                        <li class="nav-item"><a href="/foo/baz/" class="nav-link">Baz</a></li>
                    </ul>
                    </li>
                <li class="dropdown nav-item"><a href="/alfa/" class="nav-link dropdown-toggle" id="dropdown1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Alfa</a>
                    <ul class="dropdown-menu" aria-labelledby="dropdown1">
                        <li class="nav-item"><a href="/alfa/beta/" class="dropdown-item">Beta</a></li>
                    </ul>
                    </li>
            </ul>
        </ul>
    </nav>


CODE - WORKS (Bootstrap 3)

    <div class="navbar">
        <div class="container">
            <?php
                $treemenu = $modules->get("MarkupSimpleNavigation");
                echo $treemenu->render([
                    'max_levels' => 2,
                    'levels' => false,
                    'show_root' => true,
                    'parent_class' => 'active',
                    'current_class' => 'active',
                    'has_children_class' => 'dropdown',
                    'outer_tpl' => "<ul class='nav navbar-nav vertical-align-bottom'>||{$editlink}</ul>",
                    'inner_tpl' => '<ul class="dropdown-menu">||</ul>',
                    'code_formatting' => true,
                ], $page);
            ?>
        </div>
    </div>


See also:
https://getbootstrap.com/docs/4.0/components/navbar/
https://getbootstrap.com/docs/4.0/components/dropdowns/

 

Link to comment
Share on other sites

8 hours ago, SwimToWin said:

Issue posted in separate topic (to prevent this topic from becoming too long):
MarkupSimpleNavigation - Navigation menu with dropdowns in Bootstrap 4

@SwimToWin

Moderator note:

I understand the concern of topics becoming too long (and it is something we are looking into), however, I am afraid we do not address the issue in this manner, i.e., by starting other topics in other places. This is MarkupSimpleNavigation's support forum, hence, it is the correct place to discuss your issue. Thus, I have reverted your topic here.

 

  • Like 1
Link to comment
Share on other sites

@Soma You may be right that the request is beyond "simple navigation". It's a cool module and has worked well for me in many other projects.

I have created a plain Processwire solution that supports dropdowns and multi-language using Bootstrap 4 markup, will post it when time allows.

Link to comment
Share on other sites

  • 1 month later...

Hello,

Im having some problems making my menu to look like it should. I tried everithing, just can't figure it out. Any help is appreciated. ;) Im using MarkupSimpleNavigation.

My HTML looks like:


					<ul class="navbar-nav ml-auto">
						<li class="nav-item active">
							<a class="nav-link" href="index.html"><span class="sr-only">(current)</span>Home</a>
						</li>

						<li class="nav-item dropdown drop_single ">
							<a class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" href="javascript:void(0)">Pages</a>
							<ul class="dropdown-menu dd_first">
								<li><a href="page-aboutus.html">About Us</a></li>
								<li><a href="page-team.html">Team</a></li>
								<li><a href="page-member-details.html">Profile</a></li>
							</ul>
						</li>
					</ul>

I tried with: And many other combinations ...

<?php 

$options = array(
	'parent_class' => 'nav-link dropdown-toggle',
    'current_class' => 'current',
    'has_children_class' => 'nav-item dropdown drop_single',
    'levels' => true,
    'levels_prefix' => 'level-',
    'max_levels' => null,
    'firstlast' => false,
    'collapsed' => false,
    'show_root' => true,
    'selector' => '',
    'selector_field' => 'nav_selector',
    'outer_tpl' => '<ul class="navbar-nav ml-auto">||</ul>',
    'inner_tpl' => '<ul class="dropdown-menu dd_first">||</ul>',
    'list_tpl' => '<li%s>||</li>',
    'list_field_class' => '{nav-item dropdown drop_single}',
    'item_tpl' => '<a href="{url}" class="nav-link dropdown-toggle"><span class="sr-only">(current)</span>{title}</a>',
    'item_current_tpl' => '<a href="{url}"><span class="sr-only">(current)</span>{title}</a>',
    'xtemplates' => '',
    'xitem_tpl' => '<a href="{url}" class="nav-link"><span class="sr-only">(current)</span>{title}</a>',
    'xitem_current_tpl' => '<span>{title}</span>',
    'date_format' => 'Y/m/d',
    'code_formatting' => false,
    'debug' => false
);

$treeMenu = $modules->get("MarkupSimpleNavigation"); // load the module
echo $treeMenu->render($options);

?>

But can't get it right, not sure where Im wrong here.

 

Thank you very much

R

Edited by kongondo
Moderator Note: Moved your post to the module's support forum
Link to comment
Share on other sites

Guys, me again. I'm still trying to wrap my head around this module. How can I achieve the following structure:

Home
-- Submenu 1 (anchor #)
-- Submenu 2 (anchor #)
...

Products
-- Submenu 1 (anchor #)
-- Submenu 2 (anchor #)
...

and so on.... I need a clickable first menu-level (home and products are main sites and need to remain clickable). and then I need the submenus to be anchors, so clicking on the link jumps to the correct position on this or the other page. Is this possible. Or is it done differently in Processwire? Url segments maybe (tried to understand this, but no luck..)?

Thanks for any help...

Link to comment
Share on other sites

MarkupSimpleNavigation is really nice if you show the real path of your document structure in your url.

But in your case you always show the parents url, then I would go another way and do it yourself like:

echo '<ul>';
foreach($pages->get('/')->children as $item){
  $class = '';// for marking the parent li

  if($item->id == $page->id) { $class = "parent"; }
  echo "<li class='{$class}'><a href='{$item->url}'>{$item->title}</a>";// open toplevel li
  // if there are childpages
  if($item->children){
    echo '<ul>';
    foreach($item->children as $anchor){
      // you would have to set the anchor targets to the name of the page
      // note: $item->url # $anchor->url because you need the parents url 
      echo "<li><a href='{$item->url}#{$anchor->name}'>{$anchor->title}</a></li>";
    }
    echo '</ul>';
  }
  echo '</li>';// close toplevel link li
}
echo '</ul>';

 

  • Like 2
Link to comment
Share on other sites

On 08/11/2017 at 9:10 PM, Roych said:

Im having some problems making my menu to look like it should. I tried everithing, just can't figure it out. Any help is appreciated. ;) Im using MarkupSimpleNavigation.

My HTML looks like:



					<ul class="navbar-nav ml-auto">
						<li class="nav-item active">
							<a class="nav-link" href="index.html"><span class="sr-only">(current)</span>Home</a>
						</li>

						<li class="nav-item dropdown drop_single ">
							<a class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" href="javascript:void(0)">Pages</a>
							<ul class="dropdown-menu dd_first">
								<li><a href="page-aboutus.html">About Us</a></li>
								<li><a href="page-team.html">Team</a></li>
								<li><a href="page-member-details.html">Profile</a></li>
							</ul>
						</li>
					</ul>

I tried with: And many other combinations ...

@Roych

What sort of output are you getting with your MarkupSimpleNavigation code? We can't tell what is not working if we can't see the output :).

Link to comment
Share on other sites

On 10.11.2017 at 9:11 AM, Donald said:

Hi everyone,

I just do not understand how to use css styles with markup simple navigation in the right way.

Could anyone post very basic examples for a complete markup simple navigation tree (with the options and the css styles) for a very basic responsive recursive navigation. If possible with hamburger button for small displays or a basic recursive accordeon  navigation.

Very basic examples would help as long the navigation is responsive and recursive and as the styles already added.

There's nothing special about it. Just as you normally would style a navigation. The module doesn't do that for you, it just outputs a nice clean nested UL, just a few classes for parents and active.

https://www.smartmenus.org/docs/ Is a simple JS Script to generate dropdowns and also resposive. You can drop the smartmenu plugin with their CSS and mobile hamburger button as in the docs (further down) and add the id and class to the outer tpl <ul id="main-nav" class="..."> of MarkupSimpleNavigation and it works out of the box,

Link to comment
Share on other sites

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
×
×
  • Create New...