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 MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for creating a new measurement object from the sum or difference between two other objects. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.
      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

       
    • By tcnet
      Session Viewer is a module for ProcessWire to list session files and display session data. This module is helpful to display the session data of a specific session or to kick out a logged in user by simply delete his session file. After installation the module is available in the Setup menu.

      The following conditions must be met for the module to work properly:
      Session files
      Session data must be stored in session files, which is the default way in ProcessWire. Sessions stored in the database are not supported by this module. The path to the directory where the session files are stored must be declared in the ProcessWire configuration which is by default: site/assets/sessions.
      Serialize handler
      In order to transform session data easier back to a PHP array, the session data is stored serialized. PHP offers a way to declare a custom serialize handler. This module supports only the default serialize handlers: php, php_binary and php_serialize. WDDX was dropped in PHP 7.4.0 and is therefore not supported by this module as well as any other custom serialize handler. Which serialize handler is actually used you can find out in the module configuration which is available under Modules=>Configure=>SessionViewer.

      Session data
      The session data can be displayed in two different ways. PHP's default output for arrays print_r() or by default for this module nice_r() offered on github: https://github.com/uuf6429/nice_r. There is a setting in the module configuration if someone prefers print_r(). Apart from the better handling and overview of the folded session data the output of nice_r() looks indeed nicer.

      Links
      ProcessWire module directory
      github.com
    • By Robin S
      Repeater Easy Sort
      Adds a compact "easy-sort" mode to Repeater and Repeater Matrix, making those fields easier to sort when there are a large number of items.
      The module also enhances Repeater Matrix by allowing a colour to be set for each matrix type. This colour is used in the item headers and in the "add new" links, to help visually distinguish different matrix types in the inputfield.
      Screencasts
      A Repeater field

      A Repeater Matrix field with custom header colours

      Easy-sort mode
      Each Repeater/Matrix item gets an double-arrow icon in the item header. Click this icon to enter easy-sort mode.
      While in easy-sort mode:
      The items will reduce in width so that more items can be shown on the screen at once. The minimum width is configurable in the field settings. Any items that were in an open state are collapsed, but when you exit easy-sort mode the previously open items will be reopened. You can drag an item left/right/up/down to sort it within the items. The item that you clicked the icon for is shown with a black background. This makes it easier to find the item you want to move in easy-sort mode. You can click an item header to open the item. An "Exit easy-sort mode" button appears at the bottom of the inputfield. Configuration
      In the field settings for Repeater and Repeater Matrix fields you can define a minimum width in pixels for items in easy-sort mode. While in easy-sort mode the items will be sized to neatly fill the available width on any screen size but will never be narrower than the width you set here.
      In the field settings for Repeater Matrix you can define a custom header colour for each matrix type using an HTML "color" type input. The default colour for this type of input is black, so when black is selected in the input it means that no custom colour will be applied to the header.
      Exclusions
      The easy-sort mode is only possible on Repeater/Matrix fields that do not use the "item depth" option.
       
      https://github.com/Toutouwai/RepeaterEasySort
      https://processwire.com/modules/repeater-easy-sort/
×
×
  • Create New...