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 eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild. 
      EDIT: You can now install it directly from the Modules directory: http://modules.processwire.com/modules/inputfield-float-range/
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Optional step value (Read more) Optional manual override of the selected value (will still adhere to the rules above) Configurable rounding of manually entered values (floor, round, ceil, disable) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant  
      Changelog
      004 (current version)
      - Make rounding of manually entered values configurable (floor, round, ceil or disable)
      - Fix small JS bug when the value-display field was not displayed
      - Update README
      003
      - Code cleanup, add some ModuleInfo data & LICENSE
      - Submit to PW Modules directory (http://modules.processwire.com/modules/inputfield-float-range/)
      002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional
      001
      - Initial release
       
      Thanks!
       
       
    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-10-18
      2019-08-08
      2019-06-15
      2019-06-02
      2019-05-25
      If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
×
×
  • Create New...