Jump to content
kongondo

Menu Builder

Recommended Posts

44 minutes ago, Jozsef said:

data protected => array ()

Hmm. This says your menu is empty.

What about this one on line # 105?

// on line #105
d($rawMenuItems,'raw menu items');

 

Share this post


Link to post
Share on other sites

That has no output at all. I'm very curious what is that, I must overlook something.

Screen Shot 2018-11-19 at 23.18.40.png

Screen Shot 2018-11-19 at 23.18.23.png

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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.

Share this post


Link to post
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.
 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

But that's the thing, there's no space in the menu name anywhere so I don't know where it came from.
I sent you a PM with login details.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

This sounds like a Twig issue. I've never used Twig so can't help, unfortunately.

Share this post


Link to post
Share on other sites

I guess you should set the rendered html to a twig variable in the php file.

Share this post


Link to post
Share on other sites

 @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

Share this post


Link to post
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 1

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
11 hours ago, csaeum said:

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

Have a look these examples:

you will need to use getMenuItems() method.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@MateThemes

Could you please share your code and the error you are getting? 

Also, make sure that you are not passing a menu name or title as the first argument of the render method. In ML setup it should be id, an array of menu items or page object. 

  • Like 1

Share this post


Link to post
Share on other sites
16 hours ago, wbmnfktr said:

Maybe this could help... if it's the same error/behaviour:

 

Thank you very much!!!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By NehaPillai
      Hello Everyone, I was trying to update SEO meta title, description and meta keywords for my website in Process Wire CMS but it saving in the backend but it is not reflecting on my website, Please help me regarding this error. Please find below attached screen shot for your ref. TIA.


    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

×
×
  • Create New...