Jump to content
Soma

MarkupSimpleNavigation

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:

 

 

Share this post


Link to post
Share on other sites

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

 

 

 

 

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@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) ...

 

 

Share this post


Link to post
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!!

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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/

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@SwimToWin I don't think I can help you on this as I have no time and no interest in maintaining bootstrap navigations. The module isn't made for it anyway. Maybe someone else who uses bootstrap stuff can help you out?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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...

Share this post


Link to post
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

Share this post


Link to post
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 :).

Share this post


Link to post
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,

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...