kongondo Posted August 25, 2017 Author Share Posted August 25, 2017 3 hours ago, Mike Rockett said: It does appear to work, but the root page is also assigned the current class when viewing any decsendant. My bad! I forgot to do that check. We check by looking at $page->parents....Since home is everybody's parents, it passes the logic. I'll fix this in the next commit. 3 hours ago, Mike Rockett said: Is there no clean way to add an option to specific menu items that states "add current class here if an included / non-included descendant is current"? RE 'specific menu items': Unlike the backend per-menu-item setting Include natural children, you cannot cherry pick which items to apply current class to. That has to be done at a global level, aka $options. For the benefit of others reading this, in this regard, 'current_class' and 'current_class_level' work globally. For 'current_class_level' = 0 we target current $page that is not part of the MB menu items (aka non-included) in order to apply 'current_class' to its NATURAL (ProcessWire) ancestors in the MB menu. For 'current_class_level' > 1, we target current $page that is either part of the MB menu or that was made part of the MB menu via 'include_children' in order to apply 'current_class' to itself as well as its Menu Builder ancestors in the MB menu if applicable. Back to Mike's question, as stated in some previous posts, for such fine-grained/specific control, I recommend using the getMenuItems() method with your own custom function. Please see this post for examples as well as custom functions + gists. Please note that currently, getMenuItems() does not support 'include_children' but it will soon. Link to comment Share on other sites More sharing options...
Mike Rockett Posted August 25, 2017 Share Posted August 25, 2017 5 minutes ago, kongondo said: My bad! I forgot to do that check. We check by looking at $page->parents....Since home is everybody's parents, it passes the logic. I'll fix this in the next commit. I thought that may be the case -- thanks! And thanks for the explanation, I understand how it works now. Link to comment Share on other sites More sharing options...
kongondo Posted August 27, 2017 Author Share Posted August 27, 2017 (edited) Update: Menu Builder Version 0.2.1. Changelog Fixed bug in 'current_class_level' where 'current_class' was being applied to 'Home' menu item when level was set to '0'. getMenuItems() now honours both locally and globally set 'include_children'. Added 'cached_menu' option to MarkupMenuBuilder to save and fetch menus from cache to speed up menu rendering if required. Added 'cached_menu_time' to set cached menu expiration time. For compatible times, see WireCache docs. Fixed bug in ProcessMenuBuilder where 'include_children' and 'm_max_level' inputs would be displayed when the page selected to add to menu was 'Home' (These options do not apply to Home). Note Cached Menu The benefits of this feature will likely be small for most sites as menu rendering is already fast. However, for cases where you have lots of items in your menu (or in your site map if you are using Menu Builder for such), you will notice some difference. In addition, since cached menus save the full menu items array to the database (JSON of items only; not the markup!), it means you avoid the internal multiple pages->get() for getting menu items. You only hit the database once or twice (WireCache) and you got your menu! The feature also works with multi-lingual sites, in which case each language's menu is cached separately. Anyway, the feature is there for those that need it. Please note that the feature does not work with getMenuItems() since in such cases you are retrieving menu items to do what you will with them (even cache them yourself if you wish). Limitations: Currently, cached menus ONLY respect 'current_class_level' 0 and 1 (the default). This is because the 'current-ness' of a menu item should not be cached! That has to be checked live [EDIT]. News features in dev branch only for now. Please let me know how it goes, thanks. Edited August 27, 2017 by kongondo Oversights and then some! 2 Link to comment Share on other sites More sharing options...
Mike Rockett Posted August 27, 2017 Share Posted August 27, 2017 @kongondo Thanks! Works like a charm now. Link to comment Share on other sites More sharing options...
kongondo Posted August 27, 2017 Author Share Posted August 27, 2017 37 minutes ago, Mike Rockett said: @kongondo Thanks! Works like a charm now. Good to know. Thanks for testing! Please note I've just pushed a new commit (but did not change versions) to fix some oversight in the last commit. It should not affect you unless you are using the cached menu feature. I've also updated my previous post. 2 Link to comment Share on other sites More sharing options...
taoguang Posted September 6, 2017 Share Posted September 6, 2017 Hi! kongondo, Menu Builder is vety easy to use and powerful, But now I'm going to add some css3 effects to the menu. Can you add a custom tpl parameter to the list item. E.g. I want to make it <li> <a href="">item name</a></li> into <li> <a href=""><span data="item name">item name</span></a></li> The final effect is like this webpage's top menu: http://mo005-3785.mo5.line1.uemo.net/list/id/37389/ Link to comment Share on other sites More sharing options...
kongondo Posted September 6, 2017 Author Share Posted September 6, 2017 4 hours ago, taoguang said: Can you add a custom tpl parameter to the list item. Hi @taoguang. Welcome to the forums. For such custom markup, I recommend you make use of the getMenuItems() method as described in this post. I am happy to assist if you do get stuck. 1 Link to comment Share on other sites More sharing options...
taoguang Posted September 7, 2017 Share Posted September 7, 2017 18 hours ago, kongondo said: 18 hours ago, kongondo said: Hi @taoguang. Welcome to the forums. For such custom markup, I recommend you make use of the getMenuItems() method as described in this post. I am happy to assist if you do get stuck. Cool! Thank you, With this method, Now I can do almost anything! 1 Link to comment Share on other sites More sharing options...
Zeka Posted September 27, 2017 Share Posted September 27, 2017 Hi @kongondo Thank you for so great module! I use 0.1.7 version of module and get PHP Notice: Array to string conversion in ...\ProcessMenuBuilder\MarkupMenuBuilder.module:922 Here is how I use it $menu_page = pages(1023); if($lang_name == "ukrainian") { $menu_page = pages(1024); } $menu = $menuModule->getMenuItems($menu_page, 1, [ "current_class_level" => 2 ]); Changing this line $menuItems = ''; to $menuItems = array(); fixes it. Am I missing something? Link to comment Share on other sites More sharing options...
kongondo Posted October 1, 2017 Author Share Posted October 1, 2017 Hi @Zeka, Yeah, PHP 7 is a little more stricter. PHP 5 forgave such indiscretions . If you could open a bug report for me so that I don't forget to fix it, I'll appreciate it (along with other issues that have been recently reported). Thanks. 1 Link to comment Share on other sites More sharing options...
Mike Rockett Posted October 1, 2017 Share Posted October 1, 2017 (edited) On 7/20/2017 at 12:38 PM, kongondo said: Update: Menu Builder Version 0.1.9. Changelog Added support for multi-lingual menu items (both PW pages and custom ones)! Thanks @Michael van Laar for 'reminder'. I'm busy with a multi-lingual site for a client, and this feature doesn't appear to work on my end - I'm getting the error "No menu items found" when switching to the only non-default language. My menu, called footerNavLeft, is set to use French, and the language tabs are being added to the menu builder (and inheriting default values as expected). When opening the site in English (default language), all is fine. The moment I switch to French, it goves the above-mentioned error. I'm rendering the menu to my view like this: $menus = wire('modules')->MarkupMenuBuilder; $view->menuFooterNavLeft = $menus->render('footerNavLeft', [ 'menu_css_class' => 'menu', ]); --- Edit: Apologies - missed the instructions (which aren't clear in the post quoted above). Using a Page ID works. Though, I hve to ask: why isn't it possible to use a menu name/title in a multi-lingual environment? Edited October 1, 2017 by Mike Rockett Oops! Link to comment Share on other sites More sharing options...
kongondo Posted October 1, 2017 Author Share Posted October 1, 2017 1 hour ago, Mike Rockett said: Apologies - missed the instructions (which aren't clear in the post quoted above). Using a Page ID works. Though, I hve to ask: why isn't it possible to use a menu name/title in a multi-lingual environment? Ahem...really Mike? ....the docs, Mike, the docs: Quote The first argument is not optional and can be a Page object, a title, name or id of a menu or an array of menu items returned from a menu's menu_items field. Note that for multilingual environments, you cannot pass the method a title or a name; only the other three choices will work. The second argument is an optional array and will fall back to defaults if no user configurations are passed to the method. Glad you got it sorted . 1 Link to comment Share on other sites More sharing options...
Mike Rockett Posted October 1, 2017 Share Posted October 1, 2017 15 minutes ago, kongondo said: Ahem...really Mike? ....the docs, Mike, the docs: Glad you got it sorted . Works flawlessly by the way. I haven't perused the source yet, but would it be possible for you to make reference by name/title work, considering that it doesn't change on a per-language basis? Link to comment Share on other sites More sharing options...
kongondo Posted October 1, 2017 Author Share Posted October 1, 2017 1 minute ago, Mike Rockett said: would it be possible for you to make reference by name/title work, considering that it doesn't change on a per-language basis? I suppose so. I struggle with the ML API to be honest and could do with some help. Do I tell PW to get the page (menu) with the title of the default language? Thanks for any pointers/code, ta. Link to comment Share on other sites More sharing options...
Mike Rockett Posted October 1, 2017 Share Posted October 1, 2017 (edited) 26 minutes ago, kongondo said: I suppose so. I struggle with the ML API to be honest and could do with some help. Do I tell PW to get the page (menu) with the title of the default language? Thanks for any pointers/code, ta. I'm no expert either, but I feel the calls made to search for menu pages in MarkupMenuBuilder.module:142-144 are a bit much... On my side, changing it to the following fixes the issue, but I honestly don't know if it breaks anything else... $menuName = $this->wire('sanitizer')->pageName($menu); $menu = $this->wire('pages')->get("name=$menuName, template=menus, parent.name=menu-builder, check_access=0"); Edited October 1, 2017 by Mike Rockett Refer to specific commit for when code changes... Link to comment Share on other sites More sharing options...
kater Posted October 2, 2017 Share Posted October 2, 2017 Wrapping inner <ul> into div? thanks for your great module! With the uikit nav + dropdown i need to wrap an inner <ul> into a <div>. Thats fairly easy with MarkupSimpleNavigation "inner_tpl" but how to do it in this case? Uikit example: <a href"#">Menuitem</a> <div uk-dropdown> <ul class="uk-nav uk-dropdown-nav">...</ul> </div> thanks! Link to comment Share on other sites More sharing options...
Mike Rockett Posted October 2, 2017 Share Posted October 2, 2017 1 hour ago, kater said: Wrapping inner <ul> into div? thanks for your great module! With the uikit nav + dropdown i need to wrap an inner <ul> into a <div>. Thats fairly easy with MarkupSimpleNavigation "inner_tpl" but how to do it in this case? Menu Builder doesn't support that out of the box, and so you'll need to use getMenuItems(), which allows you to build your menu the way you want it. Here are some gists that could guide you for your menu. 1 Link to comment Share on other sites More sharing options...
kater Posted October 2, 2017 Share Posted October 2, 2017 looking into it. thanks. Link to comment Share on other sites More sharing options...
kongondo Posted October 2, 2017 Author Share Posted October 2, 2017 8 hours ago, kater said: thanks for your great module! Glad you like it. 8 hours ago, kater said: but how to do it in this case? What Mike said . Link to comment Share on other sites More sharing options...
Zeka Posted October 6, 2017 Share Posted October 6, 2017 Hi @kongondo I have this setup: MenuItem1 Submenuitem_01( allowed children) SubmenuItem_02 ( allowed children) MenuItem2 Submenuitem_03 ( allowed children) SubmenuItem_02 ( allowed children) I'm using getMenuItems for building my menu, but the issue is that I get children of Submenuitem_02 as children only of the last Submenuitem_02 ( parent_id = id of the last Submenuitem_02 ), but I expected that I will get duplications of children pages with right parent_id for every Submenuitem_02 Of course, I can get children in my custom function but I think that in this case, getMenuItems doesn't work as expected and could be improved. What do you think about it? Thanks, Eugene. Link to comment Share on other sites More sharing options...
kongondo Posted October 6, 2017 Author Share Posted October 6, 2017 Thanks for reporting @Zeka, This line is the problem. The array index gets overwritten (since duplicate). I'll see what to do. Link to comment Share on other sites More sharing options...
kongondo Posted November 21, 2017 Author Share Posted November 21, 2017 Hi all. I am intending to ONLY support ProcessWire 3.x starting from the next version of this module. Please have a read here and let me know what you think. Thanks. Link to comment Share on other sites More sharing options...
thmsnhl Posted November 22, 2017 Share Posted November 22, 2017 I am currently getting a fatal error on a multilanguage site. On the german version, there is no problem, the menu is rendering just as expected, but when I try to open the english or dutch version I am getting the following message: Error: Exception: No menu items found! Confirm that such a menu exists and that it has menu items. (in /Applications/MAMP/htdocs/cleaninstall/site/modules/ProcessMenuBuilder/MarkupMenuBuilder.module line 959) #0 /Applications/MAMP/htdocs/cleaninstall/site/modules/ProcessMenuBuilder/MarkupMenuBuilder.module(87): MarkupMenuBuilder->throwError() #1 /Applications/MAMP/htdocs/cleaninstall/site/templates/partials/header.inc(110): MarkupMenuBuilder->render('main', Object(MenuOptions)) #2 /Applications/MAMP/htdocs/cleaninstall/wire/core/TemplateFile.php(259): require('/Applications/M...') #3 /Applications/MAMP/htdocs/cleaninstall/wire/core/Wire.php(380): ProcessWire\TemplateFile->___render() #4 /Applications/MAMP/htdocs/cleaninstall/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___render', Array) #5 /Applications/MAMP/htdocs/cleaninstall/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) #6 The mentioned line 110 of header.inc looks like this: <?php $options = array( 'menu_css_class' => 'menu-lvl-1', 'submenu_css_class' => 'menu-lvl-2', 'current_class' => 'active', 'has_children_class' => 'has_children', 'current_class_level' => 3, 'include_children' => 1 ); ?> <?php echo $menu->render('main', $options); ?> The Processwire version is 3.0.62 and yes, I already checked if there were menu items in there and I also created another menu to confirm that the error persists. Link to comment Share on other sites More sharing options...
kongondo Posted November 22, 2017 Author Share Posted November 22, 2017 (edited) 48 minutes ago, thmsnhl said: I am currently getting a fatal error on a multilanguage site. On the german version, there is no problem, the menu is rendering just as expected, but when I try to open the english or dutch version I am getting the following message: 48 minutes ago, thmsnhl said: <?php echo $menu->render('main', $options); ?> https://github.com/kongondo/MenuBuilder#api render() This method renders a menu/navigation list of a specified menu. The method accepts two arguments/parameters: render($menu, $options); The first argument is not optional and can be a Page object, a title, name or id of a menu or an array of menu items returned from a menu's menu_items field. Note that for multilingual environments, you cannot pass the method a title or a name; only the other three choices will work. The second argument is an optional array and will fall back to defaults if no user configurations are passed to the method. @thmsnhl That should resolve your issue . Edited November 22, 2017 by kongondo 1 Link to comment Share on other sites More sharing options...
thmsnhl Posted November 27, 2017 Share Posted November 27, 2017 @kongondo First: thank you for your response and sorry for my delayed reply. I had some other projects crashing my work on that one. With your help I was able to render the menu also on localized sites. The code now looks like this: <?php $options = array( 'menu_css_class' => 'menu-lvl-1', 'submenu_css_class' => 'menu-lvl-2', 'current_class' => 'active', 'has_children_class' => 'has_children', 'current_class_level' => 3, 'include_children' => 1 ); ?> <?php echo $menu->render($pages->get("id=1930"), $options); ?> But: The menu does not show the localized page titles, those are still German. Am I missing anything else? Edit: I solved it, I just realised that I was missing the following option to translate the titles. 'default_title' => 1 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