Jump to content
Soma

MarkupSimpleNavigation

Recommended Posts

I wrote some code for BS4 Nav this morning for myself.

Maybe it helps. If it is not 100% what you need, it should be very easy to change the code in echoBS4Nav and echoBS4children.

Use like this:
 

<nav class="navbar etc.....
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<?php
require_once 'turbopw.php';
$myTurbo = new ProcessWire\TurboPW($wire);
$myTurbo->echoBS4Nav("id!=1,has_parent!=2", '../');
?>
</div>

http://theowp.bplaced.net/upload/turbopw.zip

Attention, the code is very fresh! And it is not as comfortable as MenuBuilder or MSN.

Just sharing.

The rest of the code in this file has to do with the thread below. Don't worry.

 

  • Like 1

Share this post


Link to post
Share on other sites
On 6.3.2018 at 11:24 AM, Soma said:

I meant there is in the example if you remove the <ul> from the options, it would results in <ul><div><li>...</li></div></ul>, not saying bootstrap has.

I tried with a special hook to remove the <li>' on the level greater than 1. Does that work for you?


$nav = $modules->get('MarkupSimpleNavigation');

$options = array(
    'has_children_class' => 'dropdown',
    'list_tpl' => '<li%s>||</li>',
    'current_class' => 'active',
    'list_field_class' => 'nav-item',
    'max_levels' => 2,
    'item_tpl' => '<a class="nav-link gek-anim" href="{url}">{title}</a>',
    'outer_tpl' => '<ul class="navbar-nav ml-auto">||</ul>',
    'inner_tpl' => '<div class="dropdown-menu">||</div>',
    'item_current_tpl' => '<a class="nav-link active" href="{url}">{title}</a>',
);

$nav->addHookBefore("getListString", null, function($event){
    $msn = $event->object;
    if($msn->iteration > 1){ // on level 2 and greater 
        $msn->list_tpl = array("","");
    } else {
        $msn->list_tpl = array("<li%s>","</li>");
    }
});

$sidebar .= $nav->render($options);

 

ok @Soma, thanks soma for your help. There is another small problem, wich i can solve with overwrite this bootstrap.scss. The last problem is, that the <a>-tags in <div class="dropdown-menu">needs another class. With your 'Hook' (?) the a-tags getting class="nav-item" - bootstrap wants to have the <a>-tags with the class "dropdown-item".... In my opinion the bootstrap-structure is much to complex.

I tested your solution only in a short break of my work, i'll give it a try as soon as possible - maybe begining of the next week - and will have a look to the other replies to my topics.......

thx in advance

Edited by horst
deleted inapropriate wording!

Share this post


Link to post
Share on other sites

Hi, 

No swear/bad words please :) (even with *s)!

These Forums are currently quite free from them.

Thanks in advance.

Have a nice day!

Edited by Christophe
  • Like 2

Share this post


Link to post
Share on other sites

Hello, just wondering if the following is possible ive setting up a uikit menu. I have adjusted the inter_tpl to wrap the some additional DIVs around the UL. Which works fine I also need to have the inner inner UL with a different DIV around them or at the very least just default back to a UL without the additional tags. Ive tried the following code but this seems to close the the first UL of the menu after the first dropdown occurrence

    $menu->addHookAfter('getInnerStringOpen', null, 'customInnerString');
    function customInnerString(HookEvent $event){
        $item = $event->arguments('page');
        if($item->numChildren(true) && count($item->parents) > 1){
            $event->return = '<ul class="testtest">';
        }
    }

  

Iam trying to achieve this

 

<ul>
  <li>Level 1 Nav</li>
  <li class="has-sub">Level 2
		<div class="submenu">
    	<ul class="has-sub">
          <li>Item 2.1</li>
          <li class="has-sub">Level 3
            <div class="anothersub">
              <ul>
                <li>Item 3.1</li>
              </ul>
            </div>
          </li> 
          </ul></div>
   </li>
</ul>

 

Share this post


Link to post
Share on other sites

Hello @Soma, thank you for providing this module.  On one site in production, I noticed that for some reason the top level menu items change randomly in a different order.  On a page I can keep hitting the refresh button and the menu items will randomly change order.

My tree order looks like this:

Home

  • About Us
  • Support Us
  • Resources
  • Memberships

Sometimes the menu is rendered correctly and other times it renders like:

Home

  • About Us
  • Support Us
  • Memberships
  • Resources

Here is how I'm calling it: (Note: I'm using the TemplateEngineFactory module.  That is why you see the $view->set)

Spoiler

$view->set('mainMenu', $modules->get("MarkupSimpleNavigation")->render(array(
    'parent_class' => 'selected',
    'current_class' => 'selected',
    'has_children_class' => 'has-children is-dropdown-submenu-parent',
    'levels' => true,
    'levels_prefix' => 'level-',
    'max_levels' => 4,
    'firstlast' => true,
    'collapsed' => false,
    'show_root' => true,
    'selector' => 'template!=news|calendar-posting|community-event, hide_from_menus=0, sort=sort',
    'outer_tpl' => '<ul class="dropdown menu level-0" data-dropdown-menu data-force-follow="true">||</ul>',
    'inner_tpl' => '<ul class="menu sub-menu">||</ul>',
    'list_tpl' => '<li%s>||</li>',
    'list_field_class' => '',
    'item_tpl' => '<a href="{url}">{menu_title|title}</a>',
    'item_current_tpl' => '<a href="{url}">{menu_title|title}</a>',
    'code_formatting' => false,
    'debug' => false
)));

 

I have also tried it without the sort=sort, but I have the same random results.

Does anybody have any ideas as to why I'm seeing this problem?

I'm running Processwire 3.0.101.

Thank you for any help you can provide.

Share this post


Link to post
Share on other sites

I just wanted to follow up and say that my issue is strangely now gone after upgrading from Processwire 3.0.101 to 3.0.102

Share this post


Link to post
Share on other sites

Hello,

I'm having trouble creatin a menu. It wont work I tried all sorts of things here, I just got lost, not sure what to do to make it work.

The original HTML looks like this: It looks simple but Im out of ideas 😐

<ul class="nav navbar-nav">
	<li class="dropdown active"> <a href="index.html">Home</a></li>
	<li class="dropdown"> <a href="index.htm#" data-toggle="dropdown" class="dropdown-toggle js-activated">Contact<b class="caret"></b></a>
      <ul class="dropdown-menu">
          <li><a href="room-list.html">Contact 1</a></li>
          <li><a href="room-detail.html">Contact 2</a></li>
      </ul>
	</li>
</ul>

tried with:

    'parent_class' => '',
    'current_class' => 'active',
    'has_children_class' => 'dropdown',
    'levels' => true,
    'levels_prefix' => 'level-',
    'max_levels' => null,
    'firstlast' => false,
    'collapsed' => false,
    'show_root' => true,
    'selector' => 'template!=',
    'selector_field' => '',
    'outer_tpl' => '
	<ul class="nav navbar-nav">||</ul>',
    'inner_tpl' => '<ul class="dropdown-menu">||</ul>',
    'list_tpl' => '<li%s>||</li>',
    'list_field_class' => '',
    'item_tpl' => '<a href="{url}" data-toggle="dropdown" class="dropdown-toggle js-activated">{title}</a>',
    'item_current_tpl' => '<a href="{url}">{title}</a>',
    'xtemplates' => '',
    'xitem_tpl' => '<a href="{url}">{title}</a>',
    'xitem_current_tpl' => '{title}',
    'date_format' => 'Y/m/d',
    'code_formatting' => false,
    'debug' => false

It won't work. and not sure how to put the dropdown <b class="caret"></b> inside also.

Please any help is appreciated.

Thank you

R

Share this post


Link to post
Share on other sites

@Roych there's various examples around. If you read the first post you'll see a link to a gist for a bootstrap navigation. Not sure if that's what you need.

Share this post


Link to post
Share on other sites
On 6/7/2018 at 10:13 AM, Soma said:

@Roych there's various examples around. If you read the first post you'll see a link to a gist for a bootstrap navigation. Not sure if that's what you need.

Thank you, forgot about the first post, lol 😉

R

Share this post


Link to post
Share on other sites
On 5/7/2016 at 2:19 PM, Ivan Gretsky said:

@Peter Knight: I believe it is this option:


'current_class' => 'active'

 

This doesn't seem to work. It only applies 'active' to the active child link.

On a drop down menu any page/link that is active should have it's root parent marked as active too.

On my example a user has no obvious indicator of what 'section' they are on just by looking at the top navigation bar.

active-root.png

Share this post


Link to post
Share on other sites

That depends on your CSS. I have a setup with a flyout menu that goes 3 levels down and all active parents are indeed red, e.g.

#primary-menu ul li.parent > a {
	color: #e31231;
}

 

Share this post


Link to post
Share on other sites
On 6/25/2018 at 10:16 AM, bud said:

Hi everyone, could may somenone help?

Let's say I have the following navigation in my sidebar (which works just fine with the very default settings of MSN-module).

Home

Solutions
- Solutions Overview
- Solution 1
- Solution 2

Services
- Services Overview
- Service 1
- Service 2

Blog
- Blog Post 1
- Blog Post 2
- Blog  Post 3

Also let's say the current page I visit is Solutions and here comes why I need help:

Instead of rendering the menu as you can see above it should only be rendered like

 

Solutions
- Solutions Overview
- Solution 1
- Solution 2

If my current page would be Blog than only

Blog
- Blog Post 1
- Blog Post 2
- Blog  Post 3

should be rendererd.

At last I do not use any .css yet and take the MSN just as it comes with its defaults.

You would just have to find out if your on "Solutions", then use that (the current page) as the root for the MSN. SO it renders only children of Solutions.

You can get the level you're on also by using $page->parents->count which Would be 1 for Solutions, 2 for Solutions Overview. 

So there's no options to do what you want, you'd have to find out the condition via some logik and then simply use another root parent page.

Share this post


Link to post
Share on other sites
1 hour ago, Peter Knight said:

 

This doesn't seem to work. It only applies 'active' to the active child link.

On a drop down menu any page/link that is active should have it's root parent marked as active too.

On my example a user has no obvious indicator of what 'section' they are on just by looking at the top navigation bar.

active-root.png

It actually only adds active to the active nav item. All parents of the active nav items get "parent". The first options in MSN. https://github.com/somatonic/MarkupSimpleNavigation#same-with-comments

$options = array(
    'parent_class' => 'parent',
    // overwrite class name for current parent levels
  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, Soma said:

It actually only adds active to the active nav item. All parents of the active nav items get "parent". The first options in MSN. https://github.com/somatonic/MarkupSimpleNavigation#same-with-comments


$options = array(
    'parent_class' => 'parent',
    // overwrite class name for current parent levels

Cheers Soma. 

Share this post


Link to post
Share on other sites

Hello, 
how can i change the "has_children_class" for an special id ? Ex 1074. 
I have an page with automaticly created children. And in this ID 1074 it should not be generated the dropdown submenu (Bootstrap)

This is actually my code 

 

$nav = $modules->get("MarkupSimpleNavigation"); // load the module

$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 && $item->id != 1 && $item->id != 1074 ){
        $title = $item->get("title|name");
        $event->return = '<a href="#" class="dropdown-toggle" tabindex="0" data-toggle="dropdown"  aria-expanded="false" >' . $title . ' <span class="caret"></span></a>';
       }


    // submenus don't need class and data attribs
       if($item->numChildren(true) && count($item->parents) > 1 && $item->id != 1028 && $item->id != 1036 ){
        $event->return = '<a href="#">' . $item->get("title|name") . '</a>';
      }
}

$navMarkup = $nav->render(
    array(
    'parent_class' => 'parent',
    'current_class' => 'active',
    'has_children_class' => 'dropdown',
    'levels' => false,
    'levels_prefix' => 'level-',
    'max_levels' => 2,
    'firstlast' => false,
    'collapsed' => false,
    'show_root' => false,
    'selector' => '',
    'selector_field' => 'nav_selector',
    'outer_tpl' => '<ul class="nav navbar-nav">||</ul>',
    'inner_tpl' => '<ul class="dropdown-menu">||</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' => '<span>{title}</span>',
    'date_format' => 'd/m/Y',
    'code_formatting' => true,
    'debug' => true
        )
    );



 

Share this post


Link to post
Share on other sites

@Soma

I noticed that in the 1.3.6 version of your module that if a field name includes an underscore, the portion after the underscore is removed, which sometimes makes the link to the field incorrect.

For example, if I have a field named "images_repeater" then the field will instead display as "images".

This module has helped save me countless hours over the years. Thank you for providing it to the ProcessWire community.

Share this post


Link to post
Share on other sites

Is it possible to show additional markup for a specific menu item? I would like to show the number of subpages (with it's own markup) for one specific main menu item. The page is a regular page with the same template as other pages in the menu.

Would this be possible?

Share this post


Link to post
Share on other sites

Hi @dragan, thanks! I've just implemented the hook and it's working perfectly!

Thanks for pointing me in the right direction!

Share this post


Link to post
Share on other sites

Assumption: Code for Dummies ...

Hi, i'm trying to cutomize my menu to add a personal "title" to the link somthing like <a title='$child->mytitle'

I've already added a field ("mytitle", type text) in my templates. This is not the right way to do that? Am i so away from the solution?

 // top navigation consists of homepage and its visible children
                        $homepage = $pages->get('/'); 
                        $children = $homepage->children();

                        // make 'home' the first item in the navigation
                        $children->prepend($homepage); 

                        // render an <li> for each top navigation item
                        foreach($children as $child) {
                            if($child->id == $page->rootParent->id) {
                                // this $child page is currently being viewed (or one of it's children/descendents)
                                // so we highlight it as the current page in the navigation
                                echo "<li class='nav-item active' aria-current='true'><a title='$child->mytitle' class='nav-link' href='$child->url'>$child->title</a></li>";
                            } else {
                                echo "<li class='nav-item'><a title='$child->mytitle' class='nav-link' href='$child->url'>$child->title</a></li>";
                            }
                        }

Any help appreciated, thanks in advance...

Share this post


Link to post
Share on other sites

Hi, The parent url (work with me) doesn't work using MarkUpSimpleNavigation - Is there something in the options that I should be setting?

Thanks

Screen Shot 2019-07-22 at 18.53.58.png

Share this post


Link to post
Share on other sites
12 minutes ago, buster808 said:

Hi, The parent url (work with me) doesn't work using MarkUpSimpleNavigation - Is there something in the options that I should be setting?

You may need to be a bit more specific than that: what exactly do you mean when you say that the URL doesn't work? Is the screenshot from your actual site, and if so, could you add a link to that? Or is this an example that you're trying to achieve?

Note that I've merged your question to the Markup Simple Navigation support thread. When you have a question related to a specific module, post it to the existing support thread for that module – thanks!

  • Like 1

Share this post


Link to post
Share on other sites

I love this module, but I've finally found something that I can't figure out how to do.

I'm trying to style particular item(s) in the navigation different to the others by updating a class on that item, how would I do this? For example a "Donate" or "Sign up" page that I want to have more prominent styling.

I've added a checkbox to my pages to say something along the lines of  "Make me prominent in the navigation"... but I'm not quite sure how to hook that into markupsimplenavigation's options?

Is there a way to say - if this page has the checkbox checked, add the "prominent" css class to the its menu item markup?

Thanks in advance for any support :)

Share this post


Link to post
Share on other sites

Update: I hadn't read the documentation properly and was able to add a custom class to pages that had the checkbox field checkbox_nav_prominent checked 🙂

function hookGetListClass(HookEvent $event){
    $child = $event->arguments('page'); // current rendered child page
    $class = $event->arguments('class'); // the class string already present
    // any check on that child to set your custom class
    if($child->checkbox_nav_prominent == 1){
        $event->return .= " is-prominent"; // add your custom class to the existing
    }
}

 

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 teppo
      This module tracks changes, additions, removals etc. of public (as in "not under admin") pages of your site. Like it's name says, it doesn't attempt to be a version control system or anything like that - just a log of what's happened.
      At the moment it's still a work in progress and will most likely be a victim of many ruthless this-won't-work-let's-try-that-instead cycles, but I believe I've nailed basic functionality well enough to post it here.. so, once again, I'll be happy to hear any comments you folks can provide
      https://modules.processwire.com/modules/process-changelog/
      https://github.com/teppokoivula/ProcessChangelog
      How does it work?
      Exactly like it's (sort of) predecessor, Process Changelog actually consists of two modules: Process Changelog and Process Changelog Hooks. Hooks module exists only to serve main module by hooking into various functions within Pages class, collecting data of performed operations, refining it and keeping up a log of events in it's own custom database table (process_changelog.) Visible part is managed by Process Changelog, which provides users a (relatively) pretty view of the contents of said log table.
      How do you use it?
      When installed this module adds new page called Changelog under Admin > Setup which provides you with a table view of collected data and basic filtering tools See attached screenshots to get a general idea about what that page should look like after a while.
      For detailed installation instructions etc. see README.md.
       


    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      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 apeisa
      Update 31.7.2019: AdminBar is now maintained by @teppo. Modules directory entry has been updated, as well as the "grab the code" link below.
      ***
      Latest screencast: http://www.screencas...73-ab3ba1fea30c
      Grab the code: https://github.com/teppokoivula/AdminBar
      ***
      I put this Adminbar thingy (from here: http://processwire.c...topic,50.0.html) to modules section and to it's own topic.
      I recorded quick and messy screencast (really, my first screencast ever) to show what I have made so far. You can see it from here: http://www.screencas...18-1bc0d49841b4
      When the modal goes off, I click on the "dark side". I make it so fast on screencast, so it might seem a little bit confusing. Current way is, that you can edit, go back to see the site (without saving anything), continue editing and save. After that you still have the edit window, but if you click "dark side" after saving, then the whole page will be reloaded and you see new edits live.
      I am not sure if that is best way: there are some strengths in this thinking, but it is probably better that after saving there shouldn't be a possibility to continue editing. It might confuse because then if you make edits, click on dark side -> *page refresh* -> You lose your edits.
      ***
      When I get my "starting module" from Ryan, I will turn this into real module. Now I had to make some little tweaks to ProcessPageEdit.module (to keep modal after form submits). These probably won't hurt anything:
      if($this->redirectUrl) $this->session->redirect($this->redirectUrl); if(!empty($_GET['modal'])) $this->session->redirect("./?id={$this->page->id}&modal=true"); // NEW LINE else $this->session->redirect("./?id={$this->page->id}");   and...
      if(!empty($_GET['modal'])) { $form->attr('action', './?id=' . $this->id . '&modal=true'); } else { $form->attr('action', './?id=' . $this->id); // OLD LINE }  
    • By Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.54
      Composer: rockett/jumplinks
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! :)
×
×
  • Create New...