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

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

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 Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory (alpha version only available via GitHub) SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Installation
      Install the Auto Template Stubs module.
      Configuration
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Usage
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
       
      https://github.com/Toutouwai/AutoTemplateStubs
      https://modules.processwire.com/modules/auto-template-stubs/
    • By Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.60
      Composer: rockett/jumplinks
      ⚠️ NOTICE: 1.5.60 is an important security patch-release for an XSS vulnerability discovered by @phlp. It's HIGHLY RECOMMENDED that all Jumplinks users update to the latest version as soon as possible.
      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! 🙂
    • By Robin S
      Add Image URLs
      Allows images/files to be added to Image/File fields by pasting URLs.

      Usage
      Install the Add Image URLs module.
      A "Paste URLs" button will be added to all image and file fields. Use the button to show a textarea where URLs may be pasted, one per line. Images/files are added when the page is saved.
       
      https://github.com/Toutouwai/AddImageUrls
      https://modules.processwire.com/modules/add-image-urls/
×
×
  • Create New...