Jump to content

Menu Builder


kongondo

Recommended Posts

35 minutes ago, Jozsef said:

That has no output at all.

No output meaning nothing appears on screen or no output meaning Tracy says the array is empty? If the former, it means the condition on line #96 is met, meaning the menu is cached (Menu Builder cache). Did you cache the menu? Even in that case, a menu should be built from cache (unless it got deleted by mistake?). Try this on line #100 please:

d($menu, 'Cached menu');

Does it return anything?

Edited by kongondo
Link to comment
Share on other sites

That's strange. I'm not sure where the items are getting lost. Btw, my Tracy calls should have been bd() rather than d(). Please try bd() in the previous two as well as this on line 86:

bd($menuItems);

With the bd calls, have a look in the Tracy bar.

Is the site online? If I could get a temporary access, I could have a quick look.

Link to comment
Share on other sites

It's not live, unfortunately. If I do a

print_r($menuItems)

in line 86, the output is ' main_menu' instead of an array. Interestingly, there's a space before the name of the menu, I'm not sure if it's important.
I'll try to upload it to the server later today.
 

Link to comment
Share on other sites

22 minutes ago, Jozsef said:

there's a space before the name of the menu,

That's it! If you are logged in as superuser MB should have thrown an error. If not logged in or for non superusers, it will fail silently. Are you logged in as superuser? Try remove the space after that and see if it works.

Edited by kongondo
Link to comment
Share on other sites

Solved:
It turned out I had no template file for any of the pages in the menu and the module checks if pages are viewable.
Since non of the pages were viewable, menuItems returned an empty array.
Thanks @kongondo for the help and pointing me to the right direction. All is well now.

Link to comment
Share on other sites

I can't see an option to apply classes on the link itself, on the <a> tag. When using Bootstrap, links must have the nav-link class.
Did I miss something? What workaround can I use without messing with the module code?
The module is working great, this is really the only thing I missed.

Link to comment
Share on other sites

2 hours ago, Jozsef said:

I can't see an option to apply classes on the link itself, on the <a> tag.

It is not possible.

2 hours ago, Jozsef said:

When using Bootstrap, links must have the nav-link class.
Did I miss something? What workaround can I use without messing with the module code?

For such custom requirements, we suggest use of the method getMenuItems(). It gives you total freedom. Have a read here and see these examples. You'll need to do a bit of custom work. Shout if you need help.

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

  • 1 month later...

HI guys,

I'm using twig for my frontend and I'm trying to pass $options to the menu for rendering.

For some reason I can't achieve what I want, as I seem unable to pass associative arrays to the render() call in twig. I'm using markupMenuBuilder to render the menu.

I generate it as follows:   

   $menuBuilder = $modules->get('MarkupMenuBuilder');
   $options = array(
    'has_children_class' => 'has_children',
    'current_class' => 'active',
    'menu_css_id' => 'main',
    'menu_css_class' => 'nav',
);

$view->set('options', $options);
$view->set('menuBuilder', $menuBuilder);

to make menuBuilder accept the options I would have to pass them to the render function in php like this:

   echo $menu->render('sidenav', $options)

 

I can't get this to work in twig since I don't get how to pass the options to the render function when using twig. Can anyone point me in the right direction plz?

 

Best whishes deM

Link to comment
Share on other sites

  • 2 weeks later...

 @kongondo First. Thank you for this great module!

I'm writing this in the hope it can help someone.

I'm using the latest PW version. Using the module I received this error when switching to a different language from the default one.

No menu items found!

To solve the issue I went in the admin and find the Menu Builder page (under Admin>Setup)

image.png.2dbdf67448bc5d0cf75946bf3a9ca40a.png

then I edited both the "Menu Builder" page and "mainmenu" page (this a menu that I built in Menu Builder)  and set the other language to active.

image.thumb.png.5d2f99593695b7658becce45c493e988.png

It seems the module doesn't set as active new pages in languages different from default.

My PW installation by default set it to false. 

Hope this helps. Ciao

  • Like 2
Link to comment
Share on other sites

54 minutes ago, manlio said:

It seems the module doesn't set as active new pages in languages different from default.

That's correct. Full multi-lingual support has been on my todo list for a long time. Hopefully I'll get some time soon to look into it.

56 minutes ago, manlio said:

I'm writing this in the hope it can help someone.

Thanks for sharing your workaround with others.

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

I have just installed the MenuBuilder and wanted to rebuild a menu as in the standard UIKIT design of PW.

How can I get it that the submenus are in a DIV?

Can I install it somewhere in the options or in a template?

Because by default it is UL => LI => UL => LI
AT UIKIT IT IS YES BUT UL => LI => DIV => UL => LI

Thank you for your help!

Link to comment
Share on other sites

Hello!

I like to use the menu builder module. I like the freedom for the website administrator to add and remove easily pages. But if I use the menubuilder with more than one menus on a page i got an error with the language code. It is a multilanguage website.

Does anyone have experience with such an error?

Thanks for your help!

Best greetings

Gerald @mate-themes

Link to comment
Share on other sites

Hello everyone!!!

Maybe I am missing something. First I need to say the module works now fine, but as i said, i am missing something. I have following html markup:

<div class="uk-navbar-center uk-visible@m">
  <!-- Main Menu -->
  <ul class='uk-navbar-nav'>
    <li class="uk-active"><a href="/">Home</a></li>
    <li><a href="/der-schiort/">Schiort</a></li>
    <li><a href="#">Test</a>
      <div class='uk-navbar-dropdown'>
        <ul class='uk-nav uk-navbar-dropdown-nav'>
          <li><a href="/impressum/">Impressum</a></li>
          <li><a href="/datenschutz/">Datenschutz</a></li>
        </ul>
    </li>
  </ul>
</div>

And following Menubuilder Code for the Menu:

<?php
/**
* Builds a nested list (menu items) of a single menu.
* 
* A recursive function to display nested list of menu items.
*
* @access private
* @param Int $parent ID of menu item.
* @param Array $menu Object of menu items to display.
* @param Int $first Helper variable to designate first menu item.
* @return string $out.
*
*/
function buildMenuFromObject($parent = 0, $menu, $first = 0) {
  if(!is_object($menu)) return;
  $out = '';
  $has_child = false;
  foreach ($menu as $m) {
    $newtab = $m->newtab ? " target='_blank'" : '';            
    // if this menu item is a parent; create the sub-items/child-menu-items
    if ($m->parentID == $parent) {// if this menu item is a parent; create the inner-items/child-menu-items
        // if this is the first child
        if ($has_child === false) {                    
            $has_child = true;// This is a parent                        
            if ($first == 0){                            
              $out .= "<ul class='uk-navbar-nav'>\n";                            
              $first = 1;
            }                        
            else $out .= "\n<div class='uk-navbar-dropdown'>\n<ul class='uk-nav uk-navbar-dropdown-nav'>\n";
        }
        $class = $m->isCurrent ? ' class="uk-active"' : '';
        // a menu item
        $out .= '<li' . $class . '><a href="' . $m->url . '"' . $newtab . '>' . $m->title;                    
        // if menu item has children
        if ($m->isParent) {
          $out .= '</a>';
        }
        
        else $out .= '</a>';         
        // call function again to generate nested list for sub-menu items belonging to this menu item. 
        $out .= buildMenuFromObject($m->id, $menu, $first);
        $out .= "</li>\n";
    }// end if parent
  
  }// end foreach
  if ($has_child === true) $out .= "</ul>\n";
  return $out;
}
##################################
/* grab menu items using MarkupMenuBuilder */
$mb = $modules->get('MarkupMenuBuilder');// get Menu Builder
/* get menu the menu we want (i.e. a menu created and published using ProcessMenuBuilder) */
// we can pass the menu's Page, page ID, title, name or its menu items string to getMenuItems()
#$menu = $pages->get(1299);// pass a Page
$menu = 1041;// pass an ID
#$menu = 'main';// pass a name
// passing an array
#$jsonStr = $pages->get(1299)->menu_items;
#$arrayFromJSON = json_decode($jsonStr, true);
#$menu = $arrayFromJSON;// pass an array
#$menu = 'Main';// pass a title
/* only these 3 options apply to getMenuItems() */
$options = array('default_title'=> 1, 'default_class'=> 'cool_menu_class', 'current_class_level' => 4);
/* grab menu items as a WireArray with Menu objects */
$menuItems = $mb->getMenuItems($menu, 2, $options);// called with options and 2nd argument = 2 {return Menu (WireArray object)}
#$menuItems = $mb->getMenuItems($menu);// if calling without without options; 2nd argument defaults to 2
?>
<?php
  // build menu from array (example 1b only)
  echo buildMenuFromObject(0, $menuItems);
?>

How can I close the <div class="uk-navbar-dropdown">? Everything I've tried seems not to work!

Thank you very much for your help!!!

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