kongondo Posted January 13, 2015 Share Posted January 13, 2015 (edited) 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...) https://github.com/somatonic/MarkupSimpleNavigation#added-support-for-nav_selector-propertyfield-and-selector_leveln-new-in-121 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 January 13, 2015 by kongondo Link to comment Share on other sites More sharing options...
ndolph Posted January 13, 2015 Share Posted January 13, 2015 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...) https://github.com/somatonic/MarkupSimpleNavigation#added-support-for-nav_selector-propertyfield-and-selector_leveln-new-in-121 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? Link to comment Share on other sites More sharing options...
kongondo Posted January 13, 2015 Share Posted January 13, 2015 (edited) 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 January 13, 2015 by kongondo 2 Link to comment Share on other sites More sharing options...
ndolph Posted January 15, 2015 Share Posted January 15, 2015 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. Link to comment Share on other sites More sharing options...
kongondo Posted January 15, 2015 Share Posted January 15, 2015 I am afraid I don't follow ...I let others chime in... Link to comment Share on other sites More sharing options...
Soma Posted January 16, 2015 Author Share Posted January 16, 2015 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>")); 2 Link to comment Share on other sites More sharing options...
anyway Posted January 30, 2015 Share Posted January 30, 2015 (edited) 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 January 30, 2015 by kongondo Hi. Moved your topic to MSN support forum Link to comment Share on other sites More sharing options...
Soma Posted January 30, 2015 Author Share Posted January 30, 2015 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? Link to comment Share on other sites More sharing options...
kater Posted January 31, 2015 Share Posted January 31, 2015 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> Link to comment Share on other sites More sharing options...
Soma Posted February 2, 2015 Author Share Posted February 2, 2015 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); 3 Link to comment Share on other sites More sharing options...
kater Posted February 3, 2015 Share Posted February 3, 2015 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! Link to comment Share on other sites More sharing options...
anyway Posted February 5, 2015 Share Posted February 5, 2015 Okay... thanks for the jquery hint, Soma. I could solve it like that: $('.has-dropdown > a').click(function(e){ e.preventDefault(); }); Easier than expected Link to comment Share on other sites More sharing options...
ndolph Posted February 16, 2015 Share Posted February 16, 2015 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. Link to comment Share on other sites More sharing options...
Mats Posted March 3, 2015 Share Posted March 3, 2015 (edited) 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 March 3, 2015 by Mats Link to comment Share on other sites More sharing options...
Soma Posted March 3, 2015 Author Share Posted March 3, 2015 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. Link to comment Share on other sites More sharing options...
Mats Posted March 3, 2015 Share Posted March 3, 2015 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! Link to comment Share on other sites More sharing options...
bbeer Posted March 26, 2015 Share Posted March 26, 2015 Hi all is it possible to use MarkupSimpleNavigation to output just certain pages for a special navigation, i.e. by page id's? Link to comment Share on other sites More sharing options...
diogo Posted March 26, 2015 Share Posted March 26, 2015 Hi bbeer, here you have https://github.com/somatonic/MarkupSimpleNavigation#build-a-menu-using-a-pagearray-instead-of-a-single-root-page 1 Link to comment Share on other sites More sharing options...
bbeer Posted March 26, 2015 Share Posted March 26, 2015 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? Link to comment Share on other sites More sharing options...
adrian Posted March 26, 2015 Share Posted March 26, 2015 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"); 2 Link to comment Share on other sites More sharing options...
bbeer Posted March 26, 2015 Share Posted March 26, 2015 Adrian thanks a lot, works like a charm. 1 Link to comment Share on other sites More sharing options...
houseofdeadleg Posted March 30, 2015 Share Posted March 30, 2015 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? Link to comment Share on other sites More sharing options...
DaveP Posted March 30, 2015 Share Posted March 30, 2015 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 Link to comment Share on other sites More sharing options...
houseofdeadleg Posted March 30, 2015 Share Posted March 30, 2015 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. Link to comment Share on other sites More sharing options...
DaveP Posted March 30, 2015 Share Posted March 30, 2015 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now