kongondo

Menu Builder

Recommended Posts

Hey @kongondo I just recently came across this module in a existing PW project I had to take over. I knew about it's existence but never tried it myself. Great and useful features, thanks!

 

  • Like 1

Share this post


Link to post
Share on other sites

Update: Menu Builder Version 0.1.6.

Changelog

  1. Fixed a JS issue that stopped 'select all' checkbox from working in Menu Builder dashboard
  2. Fixed InputfieldMarkup issue that prevented HTML in description not to be properly rendered. Thanks @Jonathan Lahijani and @Michael van Laar
Menu Builder is now PW2.8 + PW3.x compatible! (first one of mine off the blocks!)
  • Like 4

Share this post


Link to post
Share on other sites

Hi,

Great module - it's just what I needed!

However, I'm encountering a weird issue with some menu item titles.

If a menu item title contains an apostrophe/single-quote, the characters following (and including) the apostrophe are removed after saving the menu.

For example, the title "What's On" becomes "What".

It's ok if it is the initial save after adding that menu item, the apostrophed title is saved to the db, but it is subsequent saves that remove it.

It appears the characters are stripped when the title is displayed in Menu Builder's menu item editor widget.

Currently, the work around is to just retype each menu item that gets stripped before saving each time.

Using:
Menu Builder:  ver. 0.1.6
Processwire:     ver. 3.0.47

  • Like 2

Share this post


Link to post
Share on other sites

Update: Menu Builder Version 0.1.7.

Changelog

  1. Fixed a bug that caused titles of menu items with apostrophes not to display properly in menu settings. Thanks @LMD
  2. Code cleanup and refactoring.
  • Like 2

Share this post


Link to post
Share on other sites
13 minutes ago, kongondo said:

Update: Menu Builder Version 0.1.7.

Changelog

  1. Fixed a bug that caused titles of menu items with apostrophes not to display properly in menu settings. Thanks @LMD
  2. Code cleanup and refactoring.

Gosh that was quick. Works a charm. Thanks!

  • Like 1

Share this post


Link to post
Share on other sites

Hello,

I recently installed MB on my multi-language's website in progress. I'm quite sure it was working in both languages. But since couple of days, I noticed this error

 

Exception: No menu items found! Confirm that such a menu exists and that it has menu items. (in /multimedia/sites/dev-wire/site/assets/cache/FileCompiler/site/modules/MarkupMenuBuilder/MarkupMenuBuilder.module line 961)

#0 /multimedia/sites/dev-wire/site/assets/cache/FileCompiler/site/modules/MarkupMenuBuilder/MarkupMenuBuilder.module(88): MarkupMenuBuilder->throwError()
#1 /multimedia/sites/dev-wire/site/templates/_main.php(194): MarkupMenuBuilder->render('main', Array)
#2 /multimedia/sites/dev-wire/wire/core/TemplateFile.php(276): require('/multimedia/sit...')
#3 /multimedia/sites/dev-wire/wire/core/Wire.php(374): ProcessWire\TemplateFile->___render()
#4 /multimedia/sites/dev-wire/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___render', Array)
#5 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array)
#6 /multimedia/sites/dev-wire/wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array)
#7 /multimedia/sites/dev-wire/wire/modules/PageRender.module(514): ProcessWire\TemplateFile->render()
#8 [internal function]: ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent))
#9 /multimedia/sites/dev-wire/wire/core/Wire.php(376): call_user_func_array(Array, Array)
#10 /multimedia/sites/dev-wire/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___renderPage', Array)
#11 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\PageRender), 'renderPage', Array)
#12 /multimedia/sites/dev-wire/wire/core/WireHooks.php(782): ProcessWire\Wire->__call('renderPage', Array)
#13 /multimedia/sites/dev-wire/wire/core/WireHooks.php(782): ProcessWire\PageRender->renderPage(Object(ProcessWire\HookEvent))
#14 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Page), 'render', Array)
#15 /multimedia/sites/dev-wire/wire/modules/Process/ProcessPageView.module(205): ProcessWire\Wire->__call('render', Array)
#16 /multimedia/sites/dev-wire/wire/modules/Process/ProcessPageView.module(205): ProcessWire\Page->render()
#17 [internal function]: ProcessWire\ProcessPageView->___execute(true)
#18 /multimedia/sites/dev-wire/wire/core/Wire.php(376): call_user_func_array(Array, Array)
#19 /multimedia/sites/dev-wire/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___execute', Array)
#20 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessPageView), 'execute', Array)
#21 /multimedia/sites/dev-wire/index.php(55): ProcessWire\Wire->__call('execute', Array)
#22 /multimedia/sites/dev-wire/index.php(55): ProcessWire\ProcessPageView->execute(true)
#23 {main}

I'm currently running PW 3.0.50, but I'm unable to say what version it was when I previously installed.

I have 2 menus, but removing one or the other give the same error.

I call my menu by

    $options = array(
                        'wrapper_list_type' => 'ul',//ul, ol, nav, div, etc.
                        'menu_css_class' => 'topnav',//a CSS Class for the menu
                        'current_class' => 'active',
                            );
                            
                            
                            $menu = $modules->get('MarkupMenuBuilder');//Load the module. $menu is an example
                            echo $menu->render('main', $options);
                            

Do I doing something wrong?

Share this post


Link to post
Share on other sites

@mel47,

Please see this note on how to call a menu in a multi-lingual environment:

Quote

....The first argument is not optional and can be a Page object, a title, name or id of a menu or an array of menu items returned from a menu's menu_items field. Note that for multilingual environments, you cannot pass the method a title or a name; only the other three choices will work

If that doesn't resolve your issue, try refreshing your file compiler cache.

  • Like 2

Share this post


Link to post
Share on other sites
1 hour ago, kongondo said:

@mel47,

Please see this note on how to call a menu in a multi-lingual environment:

If that doesn't resolve your issue, try refreshing your file compiler cache.

Oh, my, my... I read it but it appears I didn't completely understood...

So solve my problem by replace with

$menu = $modules->get('MarkupMenuBuilder');//Load the module. $menu is an example
$m = $pages->get(2359);
echo $menu->render($m, $options);

 

Share this post


Link to post
Share on other sites

Hello, me again.

I've encountered another issue with Menu Builder.

This time it's related to HTML in the titles. I wanted to add FontAwesome icons to a menu, so enabled "Allow HTML in menu items title" in the settings for the menu.

I then added the FontAwesome code to the title field, like this:

pw-menubuilder-htmlprob01.jpg

When I saved the menu, it went weird and broke the editor widget (n.b. it's the same outcome using either single or double-quoted attributes):
pw-menubuilder-htmlprob02.jpg

Like the previous issue, the title does save to the DB (and when I looked at a frontend page, it showed the icon as it should), but when I tried to save the page again, the broken menu item completely disappeared (is not saved to the DB at all) and I had to add it again.

I think the menu editor widget doesn't like the HTML attributes, because it works fine with plain HTML elements without attributes.

Current Workaround:

Add a CSS class to the list item wrapper and manually add the FontAwesome icon in the site stylesheet.

Using:

Processwire:   ver 3.0.50
MenuBuilder: ver 0.1.7
 

 

Share this post


Link to post
Share on other sites

@LMD. Thanks for reporting. I haven't been able to find a suitable solution for this. The issue is the quotes are tripping up the input value. Have a look at the markup in page source; you will see class="" is output but the HTML breaks since we have something like value="<i class="fa fa-home">". For now (and for any complex menus), I suggest you use the approach posted here, whereby you will have total control over your menu items' structure and styling. 

Edited by kongondo

Share this post


Link to post
Share on other sites

@kongondo Thanks, I  got the menu working with a custom menu builder functions.

I couldn't help myself from digging around the in the the module code, though :).  I think I've found what seems to be a fairly simple solution to the quoted attributes breaking the form output.

In ProcessMenuBuilder.module, on line num. 1111:

https://github.com/kongondo/MenuBuilder/blob/bfc032cb3a07b65e732469b16b5286563bd709e9/ProcessMenuBuilder.module#L1111

Change:

<input type="text" value="' . $title . '" name="item_title[' . $id . ']" class="menu_settings" id="item_title' . $id . '">

To:

<input type="text" value="' . htmlentities($title) . '" name="item_title[' . $id . ']" class="menu_settings" id="item_title' . $id . '">

The htmlentities() function deals with the issue of quotes breaking the form input.

I've tested it on my site and it seems to be working just fine. The icons display in the front-end and the admin widget item label, and the code displays in the item's title edit field after being saved.

I don't know if I've missed anything though?

 

  • Like 2

Share this post


Link to post
Share on other sites

hello friends,

I have few children pages under a parent page.  i want to show that children page under two parents page in Main menu as well as in breadcrumbs.

With the help of menu builder main menu show same childern page under both the parents, but Breadcrumbs follow the page tree structure.

how can i get the expected result?

thank you.

Share this post


Link to post
Share on other sites

Welcome to the forums @Sahil. I have moved your topic to 'General Support'. If however, you are referring to the module Menu Builder, I will move your topic to its support forum and answer you question there. Please confirm.

Share this post


Link to post
Share on other sites
20 minutes ago, Sahil said:

I have few children pages under a parent page.  i want to show that children page under two parents page in Main menu as well as in breadcrumbs.

With the help of menu builder main menu show same childern page under both the parents, but Breadcrumbs follow the page tree structure.

how can i get the expected result?

I'll have to study this first. It's been a while since I developed the Breadcrumb component of Menu Builder :).

  • Like 1

Share this post


Link to post
Share on other sites

Love the module! I was wondering if there was a way to add Schema.org markup support for the menus? If you look at "Site Navigation Schema Markup" on this site, you'll see that there is markup that should be added to get menu pages to show up with Google results. I would like to take advantage of this. Given the simplicity of the markup, I feel if it were to be put into this module, that it would make sense to enable with a checkbox on each separate menu created. (So I would enable on the "main" menu, but not the menu on the footer, if that makes sense.) Thanks!

EDIT:
I ended up hand-coding it into MarkupMenuBuilder.module at lines 367 and 368, which is good and achieves the proper result (and validation) but unfortunately creates 2 schema menus...there is a menu on top and one at the footer. I only want one schema menu, which is the longer one in the footer. I knew going in that it would likely do that, but it's certainly preferable that it doesn't. Also, when the module gets updated, it will wipe that out and it'd have to be done again. If this could be built in that would be great. BTW, I'll attach my code below (and my neurosis prefers double quotes in rendered HTML rather than single ;))...
 

if(!$iTag) $out .= "\n\t<a{$itemCSSID}{$class}{$newtab} href=\"{$m->url}\" itemprop=\"url\">{$m->title}</a>";
else $out .= "\n\t<{$iTag}{$itemCSSID}{$class} itemprop=\"name\">\n\t\t<a{$newtab} href=\"{$m->url}\" itemprop=\"url\">{$m->title}</a>";

 

Edited by Standard Forge
Hand coded part of my request

Share this post


Link to post
Share on other sites

@Standard Forge, Glad you find the module useful :).

On 17/02/2017 at 11:24 PM, Standard Forge said:

I ended up hand-coding it into MarkupMenuBuilder.module at lines 367 and 368, which is good and achieves the proper result (and validation) but

 As you point out, that's a bad idea :P. For complex or custom menus, there's a better way to achieve the result you want. I decided not to add any more features such as these to MenuBuilder (including "Bootstrap does this or that"...sort of requests). Instead, since a while back, Menu Builder now provides an API that will return your menu items allowing you greater control over their output. This is done via the method getMenuItems(). Please find detailed examples in this post. Grab one and edit it to suit your needs. Let us know how you get along.

Share this post


Link to post
Share on other sites


@Standard Forge, if you just want to make one or two minor changes to a rendered menu without having to build all the markup yourself (using getMenuItems()), you can do a quick str_replace.

Example:

$menu = $modules->get('MarkupMenuBuilder');

// cache the rendered menu
$schema_menu = $menu->render('my-menu-name');

// alter the rendered menu to your desire
$schema_menu = str_replace('<li ', '<li itemprop="name" ', $schema_menu);
$schema_menu = str_replace('<a ', '<a itemprop="url" ', $schema_menu);

// output the altered menu
echo $schema_menu;

Quick and dirty, I know. But if you are using delayed output anyway, it’s just one or two lines of code.

  • Like 1

Share this post


Link to post
Share on other sites

Hi, 

I don't want to list pages that aren't listable by the current user in the menu. I fixt it by adding an if statement on line 192 of MarkupMenuBuilder.module:

if($this->wire('pages')->get($m->pagesID)->listable()){
	$menu->add($m);
}

Is there a better way to do this? In a hook or a setting that I have missed? :)

Share this post


Link to post
Share on other sites
2 hours ago, Peejay said:

I don't want to list pages that aren't listable by the current user in the menu

Cool idea :).

2 hours ago, Peejay said:

Is there a better way to do this?

Yes; please file a feature request, thanks.

2 hours ago, Peejay said:

In a hook or a setting that I have missed?

No need for a hook. We can simply pass an option [which I'll create] to render(). However, this will not be as straightforward as it looks. What if that unlistable menu item has children, especially ones that are custom menus? We can't leave them parentless. They will have to be removed. Such a potential situation won't always be apparent at the editing stage; editors could unknowingly create a hierarchy that will break if the option to not list menu items is applied. Please file a request and I'll have a think.

  • Like 2

Share this post


Link to post
Share on other sites

Great module.

Any plans for an enable/disable option on a menu item? Maybe a way to change a menu from one type to another? I feel like this would make it more useable by an end-user.

Share this post


Link to post
Share on other sites

Glad you like the module @cjx2240

16 minutes ago, cjx2240 said:

Any plans for an enable/disable option on a menu item?

Do you mean if disabled menu item does not show in the frontend? What's the use case? Why not just not add that menu item? 

 

16 minutes ago, cjx2240 said:

Maybe a way to change a menu from one type to another?

I don't follow. Please explain.

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 anderson
      Hi all,
      I'm a new to website building. Learned some CRASH course of js,jquery,php. Then I found CMS. Still learning around forum, youtube....
      Anyway, please help me with some beginer questions:
      1, About template - please correct me if I understand wrong : every page should be (or recommended) built on a template. So if in total I'll have 10 pages, 2 of them have same layout, I'll need 9 templates.  And, what fields a page includes, is not defined in page, but defined in the template that page uses. 
      2,  Where to see what modules I've installed? is it in "Modules - Site"? 
      3, I installed "PageTable Extended", then what?  As in a youtube tutorial, it should appear in Setup tab, but it doesn't.  What's in there: templates,fields,logs,comments. (I installed "Uikit 3 site_blog profile".)
      4, I did a search in Processwire website for the famous "repeater matrix" module, and can not find it, there's a Repeater, as well as a Matrix. Is it not a module?
      5, I watched this youtube tuts: https://www.youtube.com/watch?v=IHqnLQy9R1A
      Anybody familiar with this tuts please help: 
      After he analysed a target webpage layout he wanted to mimic, he created some fields, some template, then based on those he created a page and input some "content" in there, then clicked "view", it's just some text. So, here comes my question, he copied a folder "assets" (subfolders are: css,fonts,js,img) over, then the page have the appearance/layout he wanted to mimic. Where does that assets folder come from?
      Appreciate any help.
    • By mtwebit
      I've created a set of modules for importing (manipulating and displaying) data from external resources. A key requirement was to handle large (100k+) number of pages easily.
      Main features
      import data from CSV and XML sources in the background (using Tasker) purge, update or overwrite existing pages using selectors user configurable input <-> field mappings on-the-fly data conversion and composition (e.g. joining CSV columns into a single field) download external resources (files, images) during import handle page references by any (even numeric) fields How it works
      You can upload CSV or XML files to DataSet pages and specify import rules in their description.
      The module imports the content of the file and creates/updates child pages automatically.
      How to use it
      Create a DataSet page that stores the source file. The file's description field specifies how the import should be done:
      After saving the DataSet page an import button should appear below the file description.

      When you start the import the DataSet module creates a task (executed by Tasker) that will import the data in the background.
      You can monitor its execution and check its logs for errors.

      See the module's wiki for more details.
      The module was already used in three projects to import and handle large XML and CSV datasets. It has some rough edges and I'm sure it needs improvement so comments are welcome.
    • By dreerr
      TemplateEnginePug (formally TemplateEngineJade)
       
      This module adds Pug templates to the TemplateEngineFactory. It uses https://github.com/pug-php/pug to render templates.
      doctype html html(lang='en') head meta(http-equiv='content-type', content='text/html; charset=utf-8') title= $page->title link(rel='stylesheet', type='text/css', href=$config->urls->templates . 'styles/main.css') body include header.pug h1= $page->title if $page->editable() p: a(href=$page->editURL) Edit Project on GitHub: github.com/dreerr/TemplateEnginePug
      Project in modules directory: modules.processwire.com/modules/template-engine-pug/
       
      For common problems/features/questions about the Factory, use the TemplateEngineFactory thread.
       
    • By Robin S
      Pages At Bottom
      Keeps selected pages at the bottom of their siblings.
      A "bottom page" will stay at the bottom even if it is drag-sorted to a different location or another page is drag-sorted below it (after Page List is refreshed the bottom page will still be at the bottom).
      Newly added sibling pages will not appear below a bottom page.
      The module also prevents the API methods $pages->sort() and $pages->insertAfter() from affecting the position of bottom pages.
      Note: the module only works when the sort setting for children on the parent page/template is "Manual drag-n-drop".
      Why?
      Because you want some pages to always be at the bottom of their siblings for one reason or another. And someone requested it. 🙂
      Usage
      Install the Pages At Bottom module.
      Select one or more pages to keep at the bottom of their siblings. If you select more than one bottom page per parent then their sort order in the page list will be the same as the sort order in the module config.

       
      https://github.com/Toutouwai/PagesAtBottom
      https://modules.processwire.com/modules/pages-at-bottom/
    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/