Jump to content

Menu Builder


kongondo

Recommended Posts

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
}

 

  • Like 1
Link to comment
Share on other sites

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

Screenshot_20201107_150324.png.9aed9da2dcacbd0f86e73ae4ef76d7e0.pngScreenshot_20201107_150314.png.7cd6c390b6907855dbe36a51f90c4f08.png

Link to comment
Share on other sites

@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: 

 

  • Like 4
Link to comment
Share on other sites

  • 4 weeks later...
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:

  1. That is the structure of a menu you've built using Menu Builder? OR
  2. That is the structure of your ProcessWire page tree?

 

Link to comment
Share on other sites

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(). 

  1. Use getMenuItems() to get your menu. Better if you use the option to return a WireArray menu object. Let's call this $menu.
  2. 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.
  3. 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.
Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 2 months later...
Posted (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 by DV-JF
Found solution
Link to comment
Share on other sites

  • 2 months later...

I have just started with this wonderful Menu Builder module.👍 

  1. How can I set a rel="noopener noreferrer"" attribute
  2. How can I set title tag to my <a href menu links, which uses the menu item title?

Is there a defaultOptions?

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
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.:

  1. ProcessWire version.
  2. Multi or single language site.
  3. PHP version.
  4. Steps to reproduce, unless you mean you got that error right after the module installation finished.

Thanks.

 

Link to comment
Share on other sites

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

 

  • Like 1
Link to comment
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 Robin S
      This module lets you add some custom menu items to the main admin menu, and you can set the dropdown links dynamically in a hook if needed.
      Sidenote: the module config uses some repeatable/sortable rows for the child link settings, similar to the ProFields Table interface. The data gets saved as JSON in a hidden textarea field. Might be interesting to other module developers?
      Custom Admin Menus
      Adds up to three custom menu items with optional dropdowns to the main admin menu.
      The menu items can link to admin pages, front-end pages, or pages on external websites.
      The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon.
      Requires ProcessWire v3.0.178 or newer.
      Screenshots
      Example of menu items

      Module config for the menus

      Link list shown when parent menu item is not given a URL

      Advanced
      Setting child menu items dynamically
      If needed you can set the child menu items dynamically using a hook.
      Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']); $children = []; foreach($colours as $colour) { // Each child item should be an array with the following keys $children[] = [ 'icon' => $colour['page_icon'], 'label' => $colour['title'], 'url' => $colour['url'], 'newtab' => false, ]; } $event->return = $children; } }); Create multiple levels of flyout menus
      It's also possible to create multiple levels of flyout submenus using a hook.

      For each level a submenu can be defined in a "children" item. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $children = [ [ 'icon' => 'adjust', 'label' => 'One', 'url' => '/one/', 'newtab' => false, ], [ 'icon' => 'anchor', 'label' => 'Two', 'url' => '/two/', 'newtab' => false, 'children' => [ [ 'icon' => 'child', 'label' => 'Red', 'url' => '/red/', 'newtab' => false, ], [ 'icon' => 'bullhorn', 'label' => 'Green', 'url' => '/green/', 'newtab' => false, 'children' => [ [ 'icon' => 'wifi', 'label' => 'Small', 'url' => '/small/', 'newtab' => true, ], [ 'icon' => 'codepen', 'label' => 'Medium', 'url' => '/medium/', 'newtab' => false, ], [ 'icon' => 'cogs', 'label' => 'Large', 'url' => '/large/', 'newtab' => false, ], ] ], [ 'icon' => 'futbol-o', 'label' => 'Blue', 'url' => '/blue/', 'newtab' => true, ], ] ], [ 'icon' => 'hand-o-left', 'label' => 'Three', 'url' => '/three/', 'newtab' => false, ], ]; $event->return = $children; } }); Showing/hiding menus according to user role
      You can determine which menu items can be seen by a role by checking the user's role in the hook.
      For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); $user = $event->wire()->user; // For custom menu number 1... if($menu_number === 1) { // ...if user does not have some particular role... if(!$user->hasRole('foo')) { // ...do not show the menu $event->return = false; } } });  
      https://github.com/Toutouwai/CustomAdminMenus
      https://processwire.com/modules/custom-admin-menus/
    • By tcnet
      This module for ProcessWire sends a notification email for each failed login attempt. Similar modules exists already in the module directory of ProcessWire. However, this module is designed to notify, even if specified user doesn't exist.
      Settings
      The settings for this module are located in the menu Modules=>Configure=>LoginFailNotifier.
      Notification email
      Specifies the email address to which the notification emails should be sent.
        Email subject
      Specifies the subject line for the notification email.
        Post variables
      Specifies the $_POST variables to be included in the notification email. Each variable must be separated by a comma. For example: login_name,login_pass
        Server variables
      Specifies the $_SERVER variables to be included in the notification email. Each variable must be separated by a comma. For example: REMOTE_ADDR,HTTP_USER_AGENT
      Link to ProcessWire module directory:
      https://processwire.com/modules/login-fail-notifier/
      Link to github.com:
      https://github.com/techcnet/LoginFailNotifier
    • By Fokke
      ProcessWire 3.x markup module for rendering meta tags in HTML document head section. Note that this module is not a full-blown SEO solution, but rather a simple tool for rendering meta tags based on module configuration. Adding custom meta tags is also supported.
      Built-in meta tags
      The following meta tags are supported out-of-the-box:
      Document title consisting of page title and site name Character set Canonical Viewport Description Keywords Hreflang tags Open Graph og:title og:site_name og:type og:url og:description og:image og:image:width og:image:height Twitter meta tags twitter:card twitter:site twitter:creator twitter:title twitter:description twitter:image Facebook meta tags fb:app_id The full documentation with configurable options can be found here: https://github.com/Fokke-/MarkupMetadata
       
      Requirements:
      ProcessWire>=3.0.0 PHP >=7.1 Installation using Composer
      composer require fokke/markup-metadata Manual installation
      Download latest version from https://github.com/Fokke-/MarkupMetadata/archive/master.zip Extract module files to site/modules/MarkupMetadata directory.
    • By m.sieber
      ITRK-Service for ProcessWire
      Module for the automated transfer of imprint, data protection declaration and terms and conditions from IT-Recht Kanzlei to your ProcessWire installation
      What is ITRK Service for ProcessWire?
      ITRK-Service for ProcessWire is a free module for ProcessWire CMS. It provides an interface to the update service of IT-Recht Kanzlei, via which the legal texts of your online presence are automatically updated. In this way, the texts remain legally secure and warning-proof in the long term. Imprint, data protection declaration, revocation and general terms and conditions are currently supported.
      You can find our documentation (in german language) here: https://www.pupit.de/itrk-service-for-processwire/dokumentation/

      Download: https://www.pupit.de/itrk-service-for-processwire/
      Github: https://github.com/pupit-de/pwItrkServiceConnector
    • By LuisM
      Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Service-Provider
      It acts as a Drop-In Replacement Module to handle the Request/Response outside the ProcessWire Admin. Even tough Symfony or any other mature MVC Framework could be intimidating at first, Symprowire tries to abstract Configuration and Symfony Internals away as much as possible to give you a quick start and lift the heavy work for you.
      The main Goal is to give an easy path to follow an MVC Approach during development with ProcessWire and open up the available eco-system.
      You can find the GitHub Repo and more Information here: https://github.com/Luis85/symprowire
      Documentation
      The Symprowire Wiki https://github.com/Luis85/symprowire/wiki How to create a simple Blog with Symprowire https://github.com/Luis85/symprowire/wiki/Symprowire-Blog-Tutorial Last Update
      16.07.2021 // RC 1 v0.6.0 centralized ProcessWire access trough out the Application by wrapping to a Service https://github.com/Luis85/symprowire/releases/tag/v0.6.0-rc-1 Requirements
      PHP ^7.4 Fresh ProcessWire ^3.0.181 with a Blank Profile Composer 2 (v1 should work, not recommended) The usual Symfony Requirements Features
      Twig Dependency Injection Monolog for Symprowire Support for .env YAML Configuration Symfony Console and Console Commands Symfony Webprofiler Full ProcessWire access inside your Controller and Services Webpack Encore support Caveats
      Symfony is no small Framework and will come with a price in terms of Memory Usage and added Overhead. To give you a taste I installed Tracy Debugger alongside to compare ProcessWire profiling with the included Symfony Webprofiler

      So in a fresh install Symprowire would atleast add another 2MB of Memory usage and around 40ms in response time, should be less in production due to the added overhead of the Webprofiler in dev env
       
×
×
  • Create New...