Jump to content
Soma

MarkupSimpleNavigation

Recommended Posts

You'll get a better answer from Soma but reading the docs, I see two possibilities if I get you correctly:

Build a menu using a PageArray instead of a single root page

https://github.com/somatonic/MarkupSimpleNavigation#build-a-menu-using-a-pagearray-instead-of-a-single-root-page

nav_selector property/field and selector_leveln (new in 1.2.1) (unsure about this one...)

I'd probably go for #1 - passing a PageArray, i.e. retrieve my events using a find, sorting by -created and limiting to 5, then pass  that to MSN...I haven't tested this, mind you... :-)

Edit:

See below; need a combination of both.

Edited by kongondo

Share this post


Link to post
Share on other sites

You'll get a better answer from Soma but reading the docs, I see two possibilities if I get you correctly:

Build a menu using a PageArray instead of a single root page

https://github.com/somatonic/MarkupSimpleNavigation#build-a-menu-using-a-pagearray-instead-of-a-single-root-page

nav_selector property/field and selector_leveln (new in 1.2.1) (unsure about this one...)

I'd probably go for #1 - passing a PageArray, i.e. retrieve my events using a find, sorting by -created and limiting to 5, then pass  that to MSN...I haven't tested this, mind you... :-)

That sounds like a way of doing it, but, I don't quite know how to accomplish this... I could get the page array going and the top nav list I guess, but how would I create a sub menu for the events top nav?

Share this post


Link to post
Share on other sites

Actually a combination of both works for me...

$menu = $modules->get("MarkupSimpleNavigation");
$entries = $pages->find('template=basic-page, children.count>1, limit=10');
$options = array(
                  'max_levels' => 2,
                  'selector_level2' => 'limit=5, sort=-created',//limit the number of children to 5 (event 1 to 5)
);
//the arguments are: render($options, $page, $rootPage)
echo $menu->render($options, null, $entries);

This should hopefully get you started...

Edited by kongondo
  • Like 2

Share this post


Link to post
Share on other sites

Actually a combination of both works for me...

$menu = $modules->get("MarkupSimpleNavigation");
$entries = $pages->find('template=basic-page, children.count>1, limit=10');
$options = array(
                  'max_levels' => 2,
                  'selector_level2' => 'limit=5, sort=-created',//limit the number of children to 5 (event 1 to 5)
);
//the arguments are: render($options, $page, $rootPage)
echo $menu->render($options, null, $entries);

This should hopefully get you started...

Eh, let me start over...

The menu I have rendered now is fine. I see how I could hide things from navigation too, that is good.

I need to know how to inject an item manually into the menu. Such as...

Home Events Photos Places Things Items

Events sub menu is

Events

-Event1

-Event2

-Event3

-Event4

-Event5

-Event6

-Event7

-Event8

-Event9

I would simply hide the Events menu from the navigation, but then inject a manual Events item with the following

Events

-Event1

-Event2

-Event3

-Event4

-----------

-Show all Events

The 4 events shown would be selected by their event date and organized as such. That way I don't have an Events menu with ALL the entries in it.

I don't want to limit my menu to certain templates etc, because I use multiple templates all over the site to render data properly.

Share this post


Link to post
Share on other sites

I think kongondo is close

You can build top level entries using a PageArray.  Only top level items are supported, once MSN got a PageArray it will recursively parse the tree from those top level entries.

You could do this

$items = new PageArray();

// add pages to PageArray

$home = $pages->get("/");
$items->add($home);

$events = $pages->get("/events/");
$items->add($events);

$photos = $pages->get("/photos/");
$items->add($photos);

$options = array(
    "selector_field" => "nav_selector"
);
$nav->render($options, null, $items);

but now make use of the "selector_field" option https://github.com/somatonic/MarkupSimpleNavigation#added-support-for-nav_selector-propertyfield-and-selector_leveln-new-in-121 default it is "nav_selector". When MSN finds a page with this property (either field or added at runtime) it will take that value as a selector to find/filter the children (if it has any). 

So if you want to have a custom selector on the "/events/" page it would look like this:

$items = new PageArray();

// add pages to PageArray

$home = $pages->get("/");
$items->add($home);

$events = $pages->get("/events/");
$events->nav_selector = "limit=5, sort=-eventdatefield"; // define a selector
$items->add($events); 

$photos = $pages->get("/photos/");
$items->add($photos);

$options = array(
    "selector_field" => "nav_selector"
​);
$nav->render($options, null, $items);

Now adding a additional item at the end is something I would add using JS (jquery). And also let the "Events" top menu entry link to the full list anyway.

To get something to target the JS script you could use "inner_tpl" with a placeholder to add name or id to ul's and add that to the options array:

$options = array(
    'selector_field' => 'nav_selector',
    'outer_tpl' => '<ul id="nav">||</ul>', 
    'inner_tpl' => '<ul id="{name}">||</ul>',
);

Then do something like this with JS

$("#nav ul#events").append($("<li><a href='/events/'>more</a></li>"));
  • Like 2

Share this post


Link to post
Share on other sites

has-children not clickable with MarkupSimpleNavigation?

Hi,

I want to create a vertical navigation with Zurb Foundation, but the template is not the important thing. Every item which has children should not be clickable. That's important. I know, there are some Foundation profiles available. I'm just wondering, if that can easy be realised with MarkupSimpleNavigation, because I have it already installed for other navigation elements on the project and it's brilliant. I have tried to bring together the following two elements. Without success.

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

$options = array(
    'parent_class' => 'parent',
    'current_class' => '',
    'has_children_class' => 'has-dropdown',
    'max_levels' => 3,
    'show_root' => true,
    'selector_field' => 'nav_selector',
    'outer_tpl' => '<ul class="right">||</ul>',
    'inner_tpl' => '<ul class="dropdown">||</ul>',
    'list_tpl' => '<li%s>||</li>',
    'code_formatting' => true
);

echo $treeMenu->render($options, $page, $rootPage); // render default menu
$has_children = count($child->children) ? true : false;

if($has_children && $child !== $root) {

    $class .= 'has-dropdown'; // sub level Foundation dropdown li class
    $childUrl = "#"; // stop parents being clickable

} else {
    $childUrl = $child->url; // if does not have children, then get the page url
}

Can that be done with MarkupSimpleNavigation? I cannot get it work, but I'm not really firm in PHP.

Thank you for your help!

Edited by kongondo
Hi. Moved your topic to MSN support forum

Share this post


Link to post
Share on other sites

I'm not sure I understand and I don't know Foundation dropdown and its required markup and what makes a item clickable or not. MarkupSimpleNavigation doesn't have to do something with whether a item is clickable or not. Can't you just add some jquery to prevent that?

Share this post


Link to post
Share on other sites

Great module. Thanks alot.

Another scenario (i hope i did not miss the answer in this thread):

I'm using the Uikit framework with dropdowns which requires an attribute "data-uk-dropdown" after the "has_children_class". Please see example.

Any idea how to add this using given module options? (using jquery .attr now).

thanks!

<nav class="uk-navbar">

<ul class="uk-navbar-nav">
   <li class="uk-active"><a href="">Active</a></li>
   <li><a href="">Item</a></li>
   <li class="uk-parent" data-uk-dropdown>
       <a href="">Parent <i class="uk-icon-caret-down"></i></a>

       <div class="uk-dropdown uk-dropdown-navbar">
       <ul class="uk-nav uk-nav-navbar">
           <li><a href="#">Item</a></li>
           <li><a href="#">Another item</a></li>
           <li class="uk-nav-header">Header</li>
           <li><a href="#">Item</a></li>
           <li><a href="#">Another item</a></li>
           <li class="uk-nav-divider"></li>
           <li><a href="#">Separated item</a></li>
        </ul>
        </div>

     </li>
</ul>

</nav>

Share this post


Link to post
Share on other sites

jQuery attr seems good to me.

Another option may be str_replace on the output something like

$out = $nav->render();
$out = str_replace('class="has_children"', 'class="has_children" data-uk-dropdown', $out);
  • Like 3

Share this post


Link to post
Share on other sites

jQuery attr seems good to me.

Another option may be str_replace on the output something like

$out = $nav->render();
$out = str_replace('class="has_children"', 'class="has_children" data-uk-dropdown', $out);

I like your approach better. More reliable targeting. Thanks!

Share this post


Link to post
Share on other sites

Okay... thanks for the jquery hint, Soma. I could solve it like that:

$('.has-dropdown > a').click(function(e){
    e.preventDefault();
});

Easier than expected :-)

Share this post


Link to post
Share on other sites

I've solved my issue with the following...

$menu = $modules->get("MarkupSimpleNavigation");
$menuoptions = array(
	'parent_class' => '',
	'current_class' => 'active',
	'has_children_class' => 'dropdown',
	'outer_tpl' => '<ul class="nav navbar-nav">||</ul>',
	'inner_tpl' => '<ul class="dropdown-menu" role="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' => 'm/d/Y',
	'code_formatting' => false,
	'selector_field' => 'nav_selector',
	'debug' => false
);
function fixBootDrop($event)
{
	$link = $event->arguments('page');

	if ($link->url == '/') return; // Ignore home
	if ($link->numChildren > 0)
		$event->return = '<a href="' . $link->url . '" class="dropdown-toggle" data-toggle="dropdown">' . $link->title . '<span class="caret"></span></a>';
}

$menu_items = new PageArray();
$events = $pages->get("/events/");
$events->nav_selector = "limit=5, sort=-event_ot_date"; // define a selector
$menu_items->add($events);
$restofstuff = $pages->find("!manual_nav=1, parent=/, sort=sort");
$menu_items->add($restofstuff);
$menu->addHookAfter('getItemString', null, 'fixBootDrop');

Added the manual_nav field to pages that I want to manually render. The rest comes in with the $restofstuff. I'm sure there is a cleaner way of doing this and I'll optimize later and post results.

Share this post


Link to post
Share on other sites

Is there a way of checking if the module finds any items to display in the navigation?

What i would like to do is check if there are any navigation items found, if so show a link to the submenu further down the page (on mobile), if not don't display the link. 

Solved it with javascript instead.

Edited by Mats

Share this post


Link to post
Share on other sites

Not sure since I can't see your code. If there's no navigation generated it returns an empty string. Or you can do a find/children manually to see if there would be any pages.

Share this post


Link to post
Share on other sites

I tried to check if there was any output but i guess i must have done something wrong. I'll look at it again, thanks Soma!

Share this post


Link to post
Share on other sites

Hi all

is it possible to use MarkupSimpleNavigation to output just certain pages for a special navigation, i.e. by page id's?

Share this post


Link to post
Share on other sites

Hi Diogo

I admit, I'm a bid lost I've seen this before but somehow need some help. I lack on php.

I was trying to get the pages like

$entries = $pages->get('1049','1050'); 

but I get an error "this page is not intended for direct access". Do I have to create a  field checkbox (show_links) and then get them like this

$entries = $pages->get("/")->show_links;

or can I get them somehow by id?

Share this post


Link to post
Share on other sites

Get is for returning a single page. You are looking to return a page array of more than one page, so try this:

$entries = $pages->find("id=1049|1050");
  • Like 2

Share this post


Link to post
Share on other sites

Adrian

thanks a lot, works like a charm.

  • Like 1

Share this post


Link to post
Share on other sites

I've skimmed through all the pages relating to this module and searched the rest of the forum but haven't found an answer to my problem as yet, so apologies if this has been asked before and I've missed it.

I'm using MSN on a site to output the navigation horizontally with drop downs for subpages. All's working well, except on one dropdown where there are so many subpages that they extend below the bottom of the screen. I was wondering if it's possible to split the output of the dropdown into multiple columns so that each contains maybe 10 items?

Share this post


Link to post
Share on other sites

I should imagine you could count the dropdown items and if there are over a certain number use CSS Columns. Browser support is good (with prefixes) - http://caniuse.com/#search=columns

That's exactly what I'd like to do, the question is how? I'm not a particularly advanced PHPer, as the output is being generated from the module I'm not entirely sure when/where I should be counting.

Share this post


Link to post
Share on other sites

Assuming you are using javascript for the dropdowns (jQuery or the like), you could add a CSS class that way, and not need to change the module. If you want to post a sample of the markup you are outputting, we'll give it a go.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="optin" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="optin" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: PrivacyWire Git Repo
      Download as .zip
      I would love to hear your feedback 🙂
      CHANGELOG
      0.0.5 Multi-language support included completely (also in TextFormatter). Added possibility to async load other assets (e.g. <img type="optin" data-category="marketing" data-src="https://via.placeholder.com/300x300">) 0.0.4 Added possibility to add an imprint link to the banner 0.0.3 Multi-language support for module config (still in development) 0.0.2 First release 0.0.1 Early development
    • By MoritzLost
      This is a new module that provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Beta release
      Note that I consider this a Beta release. Since the module is relatively aggressive in deleting some caches, I would advise you to install in on a test environment before using it on a live site.
      Let me know if you're getting any errors, have trouble using the module or if you have suggestions for improvement!
      In particular, can someone let me know if this module causes any problems with the ProCache module? I don't own or use it, so I can't check. As far as I can tell, ProCache uses a folder inside the cache directory to cache static pages, so my module should be able to clear the ProCache site cache as well, I'd appreciate it if someone can test that for me.
      Future plans
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory

    • By David Karich
      Admin Page Tree Multiple Sorting
      ClassName: ProcessPageListMultipleSorting
      Extend the ordinary sort of children of a template in the admin page tree with multiple properties. For each template, you can define your own rule. Write each template (template-name) in a row, followed by a colon and then the additional field names for sorting.
      Example: All children of the template "blog" to be sorted in descending order according to the date of creation, then descending by modification date, and then by title. Type:
      blog: -created, -modified, title  Installation
      Copy the files for this module to /site/modules/ProcessPageListMultipleSorting/ In admin: Modules > Check for new modules. Install Module "Admin Page Tree Multible Sorting". Alternative in ProcessWire 2.4+
      Login to ProcessWire backend and go to Modules Click tab "New" and enter Module Class Name: "ProcessPageListMultipleSorting" Click "Download and Install"   Compatibility   I have currently tested the module only under PW 2.6+, but think that it works on older versions too. Maybe someone can give a feedback.     Download   PW-Repo: http://modules.processwire.com/modules/process-page-list-multiple-sorting/ GitHub: https://github.com/FlipZoomMedia/Processwire-ProcessPageListMultipleSorting     I hope someone can use the module. Have fun and best regards, David
    • 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 "https://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.


×
×
  • Create New...