kongondo Posted October 29, 2020 Author Posted October 29, 2020 1 hour ago, DV-JF said: So how can I check, if a specific menu has some items, is not empty or is unpublished and render it only if these conditions match? @DV-JF Use a try catch block like this: <?php namespace ProcessWire; $menuItemsAsArray = [];// only if use getMenuItems() $menu = ''; $menus = $modules->get('MarkupMenuBuilder'); try { // no error: render menu $menu = "<div>"; $menu .= $menus->render('footer-3', $scnd_options); $menu .= "</div>"; // OR IF USING getMenuItems() //$menuItemsAsArray = $menus->getMenuItems('footer-3'); } catch (\Throwable $th) { //bd($th, 'ERROR'); // get error message (No menu items found! Confirm that such a menu exists and that it has menu items.) $menu = $th->getMessage(); } // if using menu items array if(!empty($menuItemsAsArray)){ // build menu from array } 1
DV-JF Posted October 30, 2020 Posted October 30, 2020 21 hours ago, kongondo said: Use a try catch block like this: @kongondo Thank you for the hint. Another short question: Is there a possibility to add a data attribute to the menu or/and the items, when using the render function?
kongondo Posted October 30, 2020 Author Posted October 30, 2020 7 hours ago, DV-JF said: Is there a possibility to add a data attribute to the menu or/and the items, when using the render function? @DV-JF, No, there isn't. For such cases, we have getMenuItems().
picarica Posted November 7, 2020 Posted November 7, 2020 so am trying to make a simple navigation, just few dropdowns no custom classes nothing its so simple everything is dome but somehow that plugin markupmenubuilder? look how stupid it looks,i dont know why there is such a gap, and when i open submenu all the way to the right the dropdown is clipping into previous dropdown its all broken, deefault navigation has no problem what the hell is going on, i tried looking into code, and it seems that that plugin is applying left: internal css, not sure why? but how do i get rid of it? and its weird that the whole navigation is copied below footer, why is that ? why not use the HTML that already exists
dragan Posted November 7, 2020 Posted November 7, 2020 @picarica Could you please use a more civilized language in here? I'm no PW forum admin, but I'm pretty sure the F*** word is not welcome here. If you have a problem with that particular module, you should post your question in the respective support forum instead: 4
Tyssen Posted November 30, 2020 Posted November 30, 2020 If I have a menu like this: - Item 1 - Item 2 -- Item 2.1 -- Item 2.2 - Item 3 how would I output a menu just for the children of Item 2?
kongondo Posted November 30, 2020 Author Posted November 30, 2020 3 hours ago, Tyssen said: how would I output a menu just for the children of Item 2? I understand the question but I don't understand the context. 3 hours ago, Tyssen said: If I have a menu like this: What do you mean by this? Do you mean: That is the structure of a menu you've built using Menu Builder? OR That is the structure of your ProcessWire page tree?
Tyssen Posted November 30, 2020 Posted November 30, 2020 #1. #1 and #2 are almost the same except that #2 also has a custom link to a PDF file included in it.
kongondo Posted November 30, 2020 Author Posted November 30, 2020 37 minutes ago, Tyssen said: #1. #1 and #2 are almost the same except that #2 also has a custom link to a PDF file included in it. Still not 100% sure what you are saying but I'll assume you have a menu builder menu with 3 top level items (1, 2 and 3) and you only want to output the children of the top level item 2. I'll also assume you mean you want to control this programmatically, i.e. not disable the other menu items in the MB admin. If this I got it right...the easiest way of doing this is via getMenuItems(). Use getMenuItems() to get your menu. Better if you use the option to return a WireArray menu object. Let's call this $menu. Filter / find the children of item 2 inside $menu using their parent ID, e.g.: $items = $menu->find("parentID=10"); where 10 is the ID of item 2. Build a menu using $items. For a simple 2 level menu (i.e. 2 and 2.1, 2.2, etc), you can use a loop (foreach) to build the menu. Otherwise, have a look at these gists for example recursive functions.
Tyssen Posted November 30, 2020 Posted November 30, 2020 Yes, that was what I was after, thanks. ? I had been looking at getMenuItems before, but for whatever reason, it wasn't sinking in.
GEN- Posted February 7, 2021 Posted February 7, 2021 Hello, I have a problem adding menuBuilder to an existing multilingual website. When I create a new menu with a user that is not in "default language", the default menu title is empty. When I try to add new page to the menu with a user that is not in "default language", the titles and url of the new page are those of the second language even for the default tab. I tried to add menuBuilder on a new multilingual PW installation and I have the same behavior. If the user is in default language, everything works has expected. An idea of what I'm doing wrong
GEN- Posted February 11, 2021 Posted February 11, 2021 Hello, to follow up on my previous comment, I would like to know if I can expect an update on this module to fix the current bug or no?
Roych Posted March 4, 2021 Posted March 4, 2021 Hello Maybe this was already asked, but could't find anything on the forum. Is it possible to merge two menus together somehow. I have a header menu with logo in between and now Im using two separate menuesbuilders for this. I also need to have another one for mobile. So everytime I update one menu I have to update mobile separately. Any chance I could combine two menues together so I wouldn't have to update the mobile everytime? So it would show both left and right in the mobile automaticaly. my code: (mobile menu) <?php $menu = $modules->get('MarkupMenuBuilder'); $options = array( 'wrapper_list_type' => 'ul',// ul, ol, nav, div, etc. 'list_type' => 'li',// li, a, span, etc. 'menu_css_id' => '',// a CSS ID for the menu 'menu_css_class' => 'dl-menu',// a CSS Class for the menu 'submenu_css_class' => 'dl-submenu',// CSS Class for sub-menus 'has_children_class' => 'menu-item',// CSS Class for any menu item that has children 'first_class'=>'',// CSS Class for the first item in 'last_class' => '', 'current_class' => 'active', 'default_title' => 0,// 0=show saved titles;1=show actual/current titles 'include_children' => 4,// show 'natural' MB non-native descendant items as part of navigation 'm_max_level' => 1,// how deep to fetch 'include_children' 'current_class_level' => 3,// how high up the ancestral tree to apply 'current_class' 'default_class' => '',// a CSS class to apply to all menu items ); echo $menu->render(2146, $options); ?> ID Left of the logo Spoiler <?php $menu = $modules->get('MarkupMenuBuilder'); $options = array( 'wrapper_list_type' => 'ul',// ul, ol, nav, div, etc. 'list_type' => 'li',// li, a, span, etc. 'menu_css_id' => '',// a CSS ID for the menu 'menu_css_class' => 'dl-menu',// a CSS Class for the menu 'submenu_css_class' => 'menu-item',// CSS Class for sub-menus 'has_children_class' => 'sub-menu children',// CSS Class for any menu item that has children 'first_class'=>'',// CSS Class for the first item in 'last_class' => '', 'current_class' => 'active', 'default_title' => 0,// 0=show saved titles;1=show actual/current titles 'include_children' => 4,// show 'natural' MB non-native descendant items as part of navigation 'm_max_level' => 1,// how deep to fetch 'include_children' 'current_class_level' => 3,// how high up the ancestral tree to apply 'current_class' 'default_class' => '',// a CSS class to apply to all menu items ); echo $menu->render(2018, $options); ?> Right of the logo Spoiler <?php $menu = $modules->get('MarkupMenuBuilder'); $options = array( 'wrapper_list_type' => 'ul',// ul, ol, nav, div, etc. 'list_type' => 'li',// li, a, span, etc. 'menu_css_id' => '',// a CSS ID for the menu 'menu_css_class' => 'dl-menu',// a CSS Class for the menu 'submenu_css_class' => 'menu-item',// CSS Class for sub-menus 'has_children_class' => 'sub-menu children',// CSS Class for any menu item that has children 'first_class'=>'',// CSS Class for the first item in 'last_class' => '', 'current_class' => 'active', 'default_title' => 0,// 0=show saved titles;1=show actual/current titles 'include_children' => 4,// show 'natural' MB non-native descendant items as part of navigation 'm_max_level' => 1,// how deep to fetch 'include_children' 'current_class_level' => 1,// how high up the ancestral tree to apply 'current_class' 'default_class' => '',// a CSS class to apply to all menu items ); echo $menu->render(2019, $options); ?> I tried something like this: echo $menu->render(2018|2019, $options); but ofc. not working. I hope I'm making sense here Thank you R
DV-JF Posted May 5, 2021 Posted May 5, 2021 (edited) @kongondo Just another short question. Is there a possibility to set an active class to the parent of an child element being active when using the $m->render() function? Found it, seconds later ? current_class_level' => 2 @kongondo Sorry for annoying you! Edited May 5, 2021 by DV-JF Found solution
howdytom Posted July 19, 2021 Posted July 19, 2021 I have just started with this wonderful Menu Builder module.? How can I set a rel="noopener noreferrer"" attribute How can I set title tag to my <a href menu links, which uses the menu item title? Is there a defaultOptions? 1
kongondo Posted July 21, 2021 Author Posted July 21, 2021 @howdytom, Glad you like the module. There is a defaultOptions but it doesn't cover your rel and anchor tag title needs. I highly suggest you use the getMenuItems() method to build your menu and customise it however you wish. There are a number of examples at that link. Please let us know if you need further assistance. 1
Mackski Posted August 9, 2021 Posted August 9, 2021 Just installed the module with a fresh PW install and have a fatal error: $menu = $this->modules->get('MarkupMenuBuilder'); $this->navigation = $menu->render('main');
kongondo Posted August 16, 2021 Author Posted August 16, 2021 On 8/9/2021 at 1:26 AM, Mackski said: Just installed the module with a fresh PW install and have a fatal error: Sorry to hear this. A little bit more information would help, i.e.: ProcessWire version. Multi or single language site. PHP version. Steps to reproduce, unless you mean you got that error right after the module installation finished. Thanks.
Roych Posted August 18, 2021 Posted August 18, 2021 Hello, I would realy appreciate some help with building some more complexd menu. I'm kinda lost with it. I hope it can be done at all with menubuilder. Here is the HTML of what I would like to achieve. Spoiler <div class="collapse navbar-collapse fok-navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown"> <a aria-expanded="true" aria-haspopup="true" class="nav-link dropdown-toggle d-flex text-wrap" data-toggle="dropdown" href="#" id="navbarDropdownMenuLink1"> <div class="navtext w-100"> Kids toys </div> <div class="toggle-icon toggle-icon-plattform"></div> </a> <ul aria-labelledby="navbarDropdownMenuLink1" class="dropdown-menu show"> <li class="dropdown-submenu"> <a aria-expanded="" aria-haspopup="true" class="dropdown-item d-flex dropdown-toggle" href="#"> <div class="navtext w-100"> Jobs and materials </div> <div class="toggle-icon"> </div></a> <ul class="dropdown-menu"> <li class="dropdown-submenu"> <a aria-expanded="" aria-haspopup="true" class="dropdown-item d-flex dropdown-toggle" href="#"> <div class="navtext w-100"> Works </div> <div class="toggle-icon"> </div></a> <ul class="dropdown-menu"> <li class="dropdown-title">Arbeit im Überblick</li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Videoclips</a></li> </ul> </li> <li class="dropdown-submenu"> <a aria-expanded="" aria-haspopup="true" class="dropdown-item d-flex dropdown-toggle" href="#"> <div class="navtext w-100"> Fitness and Sports </div> <div class="toggle-icon"></div> </a> <ul class="dropdown-menu"> <li class="dropdown-title">Fitnes and sports reviews</li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Videoclips</a></li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Sport</a></li> <li class="dropdown-title">Free food</li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Internet on wire</a></li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Creativity</a></li> </ul> </li> <li class="dropdown-submenu"> <a aria-expanded="" aria-haspopup="true" class="dropdown-item d-flex dropdown-toggle" href="#"> <div class="navtext w-100"> Something new </div> <div class="toggle-icon"> </div> </a> <ul class="dropdown-menu"> <li class="dropdown-title">Online tour</li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Internet on wire</a></li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Creativity</a></li> <li class="dropdown-title">Free food</li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Internet on wire</a></li> <li><a aria-expanded="false" aria-haspopup="false" class="dropdown-item" href="#">Creativity</a></li> </ul> </li> </ul> </li> </ul> </li> </ul> </div> Right now I'm here with my code, it kinda works, but not as it should I got stuck. I'm not a coder so any help is greatly appreciated. Spoiler <?php $mb = $modules->get('MarkupMenuBuilder');// get Menu Builder $menu = 1119;// pass an ID $menuItems = $mb->getMenuItems($menu, 2, $options);// called with options and 2nd argument = 2 {return Menu (WireArray object)} ?> <?php function treeMenu($menuItems, $parent, $depth = 5, $first = 0) { $depth -= 0; if ($first == 0){ $out = "\n<ul class='navbar-nav mr-auto'>"; $first = 1; } else $out = "\n<ul aria-labelledby='navbarDropdownMenuLink1' class='dropdown-menu show'>"; foreach($menuItems as $m) { if ($m->parentID == $parent) { $sub = '<ul aria-labelledby="navbarDropdownMenuLink1" class="dropdown-menu show">'; $out .= "\n\t<li class='nav-item dropdown'>\n\t\t<a aria-expanded='true' aria-haspopup='true' class='nav-link dropdown-toggle d-flex text-wrap' data-toggle='dropdown' href='" . $m->url . "' id='navbarDropdownMenuLink1' ><div class='navtext w-100'> . $m->title</div>"; if($m->isParent && $depth > 0 ) { $sub = str_replace("\n", "\n\t\t", treeMenu($menuItems, $m->id, $depth, $first)); $out .= '<div class="toggle-icon toggle-icon-plattform"></div>' . '</a>' . $sub . "\n\t"; } else $out .= "</a>\n\t"; $out .="</li>\n\t"; } }// end foreach $out .= "\n</ul>"; return $out; } ?> <div class="collapse navbar-collapse fok-navbar-collapse" id="navbarSupportedContent"> <?php echo treeMenu($menuItems, 0, 5); ?> </div> I would also like to know if it is possible to start the menu from 3rd 4th or 5th child. Thank you very much R 1
Frank Schneider Posted November 14, 2021 Posted November 14, 2021 I use the MarkupMenuBuilder. For me is unclear how i can design with css. can anyone help me wit examples?
kongondo Posted November 15, 2021 Author Posted November 15, 2021 8 hours ago, Frank Schneider said: For me is unclear how i can design with css. can anyone help me wit examples? Welcome to the forums @Frank Schneider. Please have a look at Menu Builder's documentation.
kongondo Posted November 15, 2021 Author Posted November 15, 2021 (edited) @Frank Schneider, Please stick to this thread with all questions related to Menu Builder. I've merged the thread you started into this one. Thanks. Edited November 15, 2021 by kongondo clarification
Frank Schneider Posted November 15, 2021 Posted November 15, 2021 I read Dokumentation, but it not help me. Equal what i change in the options nothing change. $menu = $modules->get('MarkupMenuBuilder'); $options = array( 'has_children_class' => 'has_children', 'current_class' => 'current', 'menu_css_id' => 'main', 'menu_css_class' => 'nav', ); echo $menu->render("MainLeft", $options);
kongondo Posted November 16, 2021 Author Posted November 16, 2021 6 hours ago, Frank Schneider said: Equal what i change in the options nothing change. I am afraid I don't understand what this means. Does it mean Menu Builder is not applying those CSS classes to your menu's (MainLeft) markup?
heribertus Posted December 20, 2021 Posted December 20, 2021 How can I make a language selector menu? My first approach is a selector menu which always leads to the start page in the selected language. This is not really satisfying.
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