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 also returns nothing. That is, no output appears on screen from Tracy.

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

Will do, thanks. I don't know why I didn't think of that earlier. 🙂

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

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 joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="optin" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="optin" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: PrivacyWire Git Repo
      Download as .zip
      I would love to hear your feedback 🙂
      CHANGELOG
      0.0.5 Multi-language support included completely (also in TextFormatter). Added possibility to async load other assets (e.g. <img type="optin" data-category="marketing" data-src="https://via.placeholder.com/300x300">) 0.0.4 Added possibility to add an imprint link to the banner 0.0.3 Multi-language support for module config (still in development) 0.0.2 First release 0.0.1 Early development
    • By MoritzLost
      This is a new module that provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Beta release
      Note that I consider this a Beta release. Since the module is relatively aggressive in deleting some caches, I would advise you to install in on a test environment before using it on a live site.
      Let me know if you're getting any errors, have trouble using the module or if you have suggestions for improvement!
      In particular, can someone let me know if this module causes any problems with the ProCache module? I don't own or use it, so I can't check. As far as I can tell, ProCache uses a folder inside the cache directory to cache static pages, so my module should be able to clear the ProCache site cache as well, I'd appreciate it if someone can test that for me.
      Future plans
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory

    • By David Karich
      Admin Page Tree Multiple Sorting
      ClassName: ProcessPageListMultipleSorting
      Extend the ordinary sort of children of a template in the admin page tree with multiple properties. For each template, you can define your own rule. Write each template (template-name) in a row, followed by a colon and then the additional field names for sorting.
      Example: All children of the template "blog" to be sorted in descending order according to the date of creation, then descending by modification date, and then by title. Type:
      blog: -created, -modified, title  Installation
      Copy the files for this module to /site/modules/ProcessPageListMultipleSorting/ In admin: Modules > Check for new modules. Install Module "Admin Page Tree Multible Sorting". Alternative in ProcessWire 2.4+
      Login to ProcessWire backend and go to Modules Click tab "New" and enter Module Class Name: "ProcessPageListMultipleSorting" Click "Download and Install"   Compatibility   I have currently tested the module only under PW 2.6+, but think that it works on older versions too. Maybe someone can give a feedback.     Download   PW-Repo: http://modules.processwire.com/modules/process-page-list-multiple-sorting/ GitHub: https://github.com/FlipZoomMedia/Processwire-ProcessPageListMultipleSorting     I hope someone can use the module. Have fun and best regards, David
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "https://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...