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 Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
    • By ukyo
      Mystique Module for ProcessWire CMS/CMF
      Github repo : https://github.com/trk/Mystique
      Mystique module allow you to create dynamic fields and store dynamic fields data on database by using a config file.
      Requirements
      ProcessWire 3.0 or newer PHP 7.0 or newer FieldtypeMystique InputfieldMystique Installation
      Install the module from the modules directory:
      Via Composer:
      composer require trk/mystique Via git clone:
      cd your-processwire-project-folder/ cd site/modules/ git clone https://github.com/trk/Mystique.git Module in live reaction with your Mystique config file
      This mean if you remove a field from your config file, field will be removed from edit screen. As you see on youtube video.
      Using Mystique with your module or use different configs path, autoload need to be true for modules
      Default configs path is site/templates/configs/, and your config file name need to start with Mystique. and need to end with .php extension.
      Adding custom path not supporting anymore !
      // Add your custom path inside your module class`init` function, didn't tested outside public function init() { $path = __DIR__ . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; Mystique::add($path); } Mystique module will search site/modules/**/configs/Mystique.*.php and site/templates/Mystique.*.php paths for Mystique config files.
      All config files need to return a PHP ARRAY like examples.
      Usage almost same with ProcessWire Inputfield Api, only difference is set and showIf usage like on example.
      <?php namespace ProcessWire; /** * Resource : testing-mystique */ return [ 'title' => __('Testing Mystique'), 'fields' => [ 'text_field' => [ 'label' => __('You can use short named types'), 'description' => __('In file showIf working like example'), 'notes' => __('Also you can use $input->set() method'), 'type' => 'text', 'showIf' => [ 'another_text' => "=''" ], 'set' => [ 'showCount' => InputfieldText::showCountChars, 'maxlength' => 255 ], 'attr' => [ 'attr-foo' => 'bar', 'attr-bar' => 'foo' ] ], 'another_text' => [ 'label' => __('Another text field (default type is text)') ] ] ]; Example:
      site/templates/configs/Mystique.seo-fields.php <?php namespace ProcessWire; /** * Resource : seo-fields */ return [ 'title' => __('Seo fields'), 'fields' => [ 'window_title' => [ 'label' => __('Window title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'attr' => [ 'placeholder' => __('Enter a window title') ] ], 'navigation_title' => [ 'label' => __('Navigation title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'showIf' => [ 'window_title' => "!=''" ], 'attr' => [ 'placeholder' => __('Enter a navigation title') ] ], 'description' => [ 'label' => __('Description for search engines'), 'type' => Mystique::TEXTAREA, 'useLanguages' => true ], 'page_tpye' => [ 'label' => __('Type'), 'type' => Mystique::SELECT, 'options' => [ 'basic' => __('Basic page'), 'gallery' => __('Gallery'), 'blog' => __('Blog') ] ], 'show_on_nav' => [ 'label' => __('Display this page on navigation'), 'type' => Mystique::CHECKBOX ] ] ]; Searching data on Mystique field is limited. Because, Mystique saving data to database in json format. When you make search for Mystique field, operator not important. Operator will be changed with %= operator.
      Search example
      $navigationPages = pages()->find('my_mystique_field.show_on_nav=1'); $navigationPages = pages()->find('my_mystique_field.page_tpye=gallery');
    • By Robin S
      This is a module I made as an experiment a while ago and never got around to releasing publicly. At the time it was prompted by discussions around using Repeater fields for "page builder" purposes, where the depth feature could possibly be used for elements that would be nested inside other elements. I thought it would be useful to enforce some depth rules and translate the depth data into a multi-dimensional array structure.
      I'm not using this module anywhere myself but maybe it's useful to somebody.
      Repeater Depth Helper
      This module does two things relating to Repeater fields that have the "Item depth" option enabled:
      It enforces some depth rules for Repeater fields on save. Those rules are:
      The first item must have a depth of zero. Each item depth must not be more than one greater than previous item depth. It provides a RepeaterPageArray::getDepthStructure helper method that returns a nested depth structure for a Repeater field value.
      Helper method
      The module adds a RepeaterPageArray::getDepthStructure method that returns a multi-dimensional array where the key is the page ID and the value is an array of nested "child" items, or null if there are no nested children.
      Example

      The module doesn't make any assumptions about how you might want to use the depth structure array, but here is a way you might use it to output a nested unordered list.
      // Output a nested unordered list from a depth structure array function outputNestedList($depth_structure, $repeater_items) { $out = "<ul>"; foreach($depth_structure as $page_id => $nested_children) { $out .= "<li>" . $repeater_items->get("id=$page_id")->title; // Go recursive if there are nested children if(is_array($nested_children)) $out .= outputNestedList($nested_children, $repeater_items); $out .= "</li>"; } $out .= "</ul>"; return $out; } $repeater_items = $page->my_repeater; $depth_structure = $repeater_items->getDepthStructure(); echo outputNestedList($depth_structure, $repeater_items);
       
      https://github.com/Toutouwai/RepeaterDepthHelper
      https://modules.processwire.com/modules/repeater-depth-helper/
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By MoritzLost
      This module allows you to integrate hCaptcha bot / spam protection into ProcessWire forms. hCaptcha is a great alternative to Google ReCaptcha, especially if you are in the EU and need to comply with privacy regulations.

      The development of this module is sponsored by schwarzdesign.
      The module is built as an Inputfield, allowing you to integrate it into any ProcessWire form you want. It's primarily intended for frontend forms and can be added to Form Builder forms for automatic spam protection. There's a step-by-step guide for adding the hCaptcha widget to Form Builder forms in the README, as well as instructions for API usage.
      Features
      Inputfield that displays an hCaptcha widget in ProcessWire forms. The inputfield verifies the hCaptcha response upon submission, and adds a field error if it is invalid. All hCaptcha configuration options for the widget (theme, display size etc) can be changed through the inputfield configuration, as well as programmatically. hCaptcha script options can be changed through a hook. Error messages can be translated through ProcessWire's site translations. hCaptcha secret keys and site-keys can be set for each individual inputfield or globally in your config.php. Error codes and failures are logged to help you find configuration errors. Please check the README for setup instructions.
      Links
      Github Repository and documentation InputfieldHCaptcha in the module directory (pending approval) Screenshots (configuration)

      Screenshots (hCaptcha widget)

       
       

       
×
×
  • Create New...