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

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 Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
      As of 11 May 2019 ProcessWire versions earlier than 3.x are not supported
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend
       

×
×
  • Create New...