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

  • 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

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?

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 monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • 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 for modifying the stored value by the value (converted as required) in another measurement. 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.

       
×
×
  • Create New...