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

@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

  • 2 months later...

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);
 
Link to comment
Share on other sites

  • 1 month later...

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
×
×
  • Create New...