Jump to content
kongondo

Menu Builder

Recommended Posts

This is the code how you would write for Pagekit CMS. I found it in a PagekitTheme. It should look very similiar in Processwire. Maybe you could change the code so that it works in Processwire.

<?php if ($root->getDepth() === 0) : ?>
<ul class="uk-navbar-nav">
<?php endif ?>

    <?php foreach ($root->getChildren() as $node) : ?>
    <li class="<?= $node->hasChildren() ? 'uk-parent' : '' ?><?= $node->get('active') ? ' uk-active' : '' ?>" <?= ($root->getDepth() === 0 && $node->hasChildren()) ? 'data-uk-dropdown':'' ?>>
        <a href="<?= $node->getUrl() ?>"><?= $node->title ?></a>

        <?php if ($node->hasChildren()) : ?>

            <?php if ($root->getDepth() === 0) : ?>
            <div class="uk-dropdown uk-dropdown-navbar">
            <?php endif ?>

                <?php if ($root->getDepth() === 0) : ?>
                <ul class="uk-nav uk-nav-navbar">
                <?php elseif ($root->getDepth() === 1) : ?>
                <ul class="uk-nav-sub">
                <?php else : ?>
                <ul>
                <?php endif ?>
                    <?= $view->render('menu-navbar.php', ['root' => $node]) ?>
                </ul>

            <?php if ($root->getDepth() === 0) : ?>
            </div>
            <?php endif ?>

        <?php endif ?>

    </li>
    <?php endforeach ?>

<?php if ($root->getDepth() === 0) : ?>
</ul>
<?php endif ?>
As an example:
 
Instead of "$node->hasChildren()" you could write "$node->numChildren(true)". Look at this navbar:
 
It is for Bootstrap but the logic is the same. Just add another div.
 
And you don´t need to use the root. I think that the MenuBuilder Module creates an array which you can use.

Share this post


Link to post
Share on other sites

Hi Mario,

Welcome to ProcessWire and the forums.

Currently, that's not possible but it is something I've been thinking about. Please see the post above yours. There's no ETA for this at the moment. Meanwhile, you can try this.

Edit: Even with the addition of 'extra attributes' such as data-xxxx, it will still not be possible to have both the inner <div> and inner <ul>, unless you try the solution I linked to above if you still want to use Menu Builder for this.

Edited by kongondo

Share this post


Link to post
Share on other sites

Thanks jannisl and kongondo for your reply! Unfortunately i'm far from knowing PHP very good. This problem here is the last step to motivate me enough to really learn PHP.  :rolleyes:

I used the github link from jannisl and tried to modify this (hopefully) working bootstrap navbar for UIKit. It looked like the easiest possibility for me to understand. I changed the classes and added the missing div. But it doesn't work. No entries in the navbar and the inspector shows only the root page. 

The modified code looks like this:

<nav class="uk-navbar">
			<ul class="uk-navbar-nav">
				<?php
				// navigation bar consists of homepage and its visible children
				if($homepage->id == $page->rootParent->id || $homepage->url == $page->menuActiveOverrideUrl) {
					echo "<li class='uk-active'>";
				} else {
					echo "<li>";
				}
				echo "<a href='//$config->httpHost$homepage->url'>$homepage->title</a></li>";
				foreach($homepage->children as $item) {
					if($item->numChildren(true)) {
						echo "<li class='uk-parent' data-uk-dropdown>";
						echo "<div class='uk-dropdown uk-dropdown-navbar'>";
						echo "<ul class='uk-nav uk-nav-navbar'>";
						foreach($item->children as $sub_item) {
							echo "<li><a href='//$config->httpHost$sub_item->url'>$sub_item->title</a></li>";
						}
						echo "</ul>";
						echo "</div>";
						echo "</li>";
					} else {
						if($item->id == $page->rootParent->id || $item->url == $page->menuActiveOverrideUrl) {
							echo "<li class='active'>";
						} else {
							echo "<li>";
						}
						echo "<a href='//$config->httpHost$item->url'>$item->title</a></li>";
					}
				}
				?>
			</ul>
		</nav>

Could someone point me to the mistakes i made?

Mario

Share this post


Link to post
Share on other sites

Because i really wanna use the Menu Builder, a friend of mine helped me to build a working solution.  ;)​  We're using the above mentioned solution from @Webrocker as a basis. Maybe it's helpful for others who wanna use the Menu Builder and the UIKit Navbar and so i post the code here: 

<nav class="uk-navbar">
						<?php
						$mainmenu_items_json =  $pages->get('name=main-menu')->menu_items; // this is the menu page in menu builder, could also be fetched with the ID
						$mainmenu_items = json_decode($mainmenu_items_json, true);

						if( count($mainmenu_items) > 0 ){
							$out = '<ul class="uk-navbar-nav">';
							foreach($mainmenu_items as $id => $item){
								$isCurrentPage = ($item['pages_id'] == $page->id || ($page->parent_id != 1 && $item['pages_id'] == $page->parent_id));

								$subs = false;

								if(!isset($item['parent_id'])) {
									$url = ($item['url']) ? $item['url'] : $pages->get($item['pages_id'])->url;
									$target = (1 == $item['newtab']) ? 'target="_blank"':'';

									foreach($mainmenu_items as $sub_id => $sub_item){
										if(isset($sub_item['parent_id']) && $sub_item['parent_id'] == $id) {
											$subs = true;
											break;
										}
									}

									$class = 'class="'.($subs ? 'uk-parent ' : '').($isCurrentPage ? 'current uk-active' : '').'"';

									$out .= '<li '.$class.($subs ? ' data-uk-dropdown="" aria-haspopup="true" aria-expanded="'.($isCurrentPage ? 'true' : 'false').'"' : '').'><a href="' . $url . '" class="" ' . $target . '>' . $item['title'] . '</a>';

									if($subs) {
										$out .= '<div class="uk-dropdown uk-dropdown-navbar uk-dropdown-bottom"><ul class="uk-nav uk-nav-navbar">';
									}

									foreach($mainmenu_items as $sub_id => $sub_item){
										if(isset($sub_item['parent_id']) && $sub_item['parent_id'] == $id) {
											$url = ($sub_item['url']) ? $sub_item['url'] : $pages->get($sub_item['pages_id'])->url;
											$target = (1 == $sub_item['newtab']) ? 'target="_blank"':'';

											$out .= '<li><a href="'.$url.'" class="'.$target.'">'.$sub_item['title'].'</a></li>';
										}
									}

									if($subs) {
										$out .= '</ul></div>';
									}

									$out .= '</li>';
								}
							}

							$out .= '</ul>';
							echo $out;
						}
						?>
					</nav> 

It's like @Webrocker says: The best of both worlds! And as a side note: My friend didn't know anything about PW before. After 15 min. he had that solution ready. I think that says everything about the flexibility and the possibilities of PW. Thanks for that CMS and the really great community here!

Mario

  • Like 3

Share this post


Link to post
Share on other sites

Hi Kongondo,

I am trying to use the Menu Builder for the past one week..

The below is used in header.tpl (smarty template)

<nav class="menu">

  	{$menu = $modules->get("MarkupMenuBuilder")}
	{$menu->render('testmenu')}

</nav>

I am able to generate the menu but without being able provide css calss for the submenus,

however as soon i add $options as mentioned in your docs like below

<nav class="menu">
  	 	{$options = array(
		        'wrapper_list_type' => 'ul',
		        'list_type' => 'li',
		        'menu_css_class' => 'type-1',
		        'submenu_css_class' => 'dropmenu',
		        'current_class' => 'active',
		        'default_title' => 0,
		        'include_children' => 4,
		        'm_max_level' => 1,
		        'current_class_level' => 1,
				)}

   	  	{$menu = $modules->get("MarkupMenuBuilder")}
		{$menu->render('testmenu', $options)}
</nav>

i get this error

Notice: Trying to get property of non-object in D:\xampp\htdocs\pw\site\modules\TemplateEngineSmarty\TemplateEngineSmarty.module on line 145

Fatal error: Exception: Syntax error in template "D:\xampp\htdocs\pw\site\templates\views\partials\header.tpl" on line 16 "'wrapper_list_type' => 'ul'," - Unexpected " => ", expected one of: "","" , ")" (in D:\xampp\htdocs\pw\site\modules\TemplateEngineSmarty\TemplateEngineSmarty.module line 109) #0 D:\xampp\htdocs\pw\site\modules\TemplateEngineFactory\TemplateEngineFactory.module(100): TemplateEngineSmarty->render() #1 D:\xampp\htdocs\pw\wire\core\Wire.php(459): TemplateEngineFactory->hookRender(Object(HookEvent)) #2 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('render', Array) #3 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Wire->__call('render', Array) #4 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Page->render() #5 [internal function]: ProcessPageView->___execute(true) #6 D:\xampp\htdocs\pw\wire\core\Wire.php(398): call_user_func_array(Array, Array) #7 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('execute', Array) #8 D:\xampp\htdocs\pw\ind in D:\xampp\htdocs\pw\index.php on line 248
Error: Exception: Syntax error in template "D:\xampp\htdocs\pw\site\templates\views\partials\header.tpl" on line 16 "'wrapper_list_type' => 'ul'," - Unexpected " => ", expected one of: "","" , ")" (in D:\xampp\htdocs\pw\site\modules\TemplateEngineSmarty\TemplateEngineSmarty.module line 109)

#0 D:\xampp\htdocs\pw\site\modules\TemplateEngineFactory\TemplateEngineFactory.module(100): TemplateEngineSmarty->render()
#1 D:\xampp\htdocs\pw\wire\core\Wire.php(459): TemplateEngineFactory->hookRender(Object(HookEvent))
#2 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('render', Array)
#3 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Wire->__call('render', Array)
#4 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Page->render()
#5 [internal function]: ProcessPageView->___execute(true)
#6 D:\xampp\htdocs\pw\wire\core\Wire.php(398): call_user_func_array(Array, Array)
#7 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('execute', Array)
#8 D:\xampp\htdocs\pw\ind

This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged.

I am not sure what i am doing wrong here ?????

Share this post


Link to post
Share on other sites

Hi @centaur78,
 
Welcome to ProcessWire and the forums. Thanks for using MenuBuilder.
 
The error is being thrown by TemplateEngineSmarty.module. I have not used that module before so I am guessing here. It probably doesn't like the single quotes. Try using double quotes, i.e.:

{$options = array(
       "wrapper_list_type" => "ul",
       "list_type" => "li",
       "menu_css_class" => "type-1",
       "submenu_css_class" => "dropmenu",
       "current_class" => "active",
       "default_title" => 0,
       "include_children" => 4,
       "m_max_level" => 1,
       "current_class_level" => 1,
)}

You also seem to be missing semi-colons at the end of your PHP statements. Is that how Smarty works?

Share this post


Link to post
Share on other sites

Thanks Kongondo for the reply

You also seem to be missing semi-colons at the end of your PHP statements. Is that how Smarty works?

Yes thats how Smarty works.

I have tried with double quote... still the same error.

As a last resort i have edited the menu properties of MarkupMenuBuilder.module.. to add these options as global. I know its not the right way ... but if there is any other way .. i will be more than happy to do it

Share this post


Link to post
Share on other sites

Maybe ask in the smarty forum. It's just a syntax error so clearly there's something it doesn't like, or you have a typo or a whitespace in there. Maybe you are supposed to be using set method or the new setMultiple() methods? I don't know, again just guessing. See if this helps:

Share this post


Link to post
Share on other sites

Hey kongondo,

Thank you very much for this great module.

Currently I am using it to buil ddropdown navigations and I would like to know if there is somethin planne like an "active trail" (class names) for the parent list items.

for e.g.

- Blog (active trail)

  - Blog Post (active)

thanks for any information.

Share this post


Link to post
Share on other sites

Hi @pmichaelis,

Glad you like the module. Have a look at the current_class_level. That in conjunction with current_class should probably do the trick (the 'active' bit).

  • Like 1

Share this post


Link to post
Share on other sites

Hi @kongondo,

I try to use this module with a multilanguage site with ProcessWire 3.0.15 (devns), but when I switch the language the menu does not show up. It only appears on the default language (german). Here is the code I used:

$menu = $modules->get('MarkupMenuBuilder');
    $options = array(
        'default_title' => 1,//0=show saved titles;1=show actual/current titles
    );

 $menu->render('mainmenu', $options));
The titles of the pages that are in the menu are translated in ProcessWire. 
Any suggestions what I can do to get it running?

Share this post


Link to post
Share on other sites

@jmartsch,

Does it work in PW 2.7.xx in your setup? I am afraid I haven't tested any of my modules in PW 3.X (haven't even had time to install this version :-X ) and won't be doing so at least until we have a stable release of PW 3..because I am really constrained for time  :(

Share this post


Link to post
Share on other sites

Hi @kongondo. 

It doesn´t even work in PW 2.7.3. When I dump  ($menu->render('mainmenu', $options)) to my Tracy Debug Bar in my main language, I see the generated code for the menu. As soon as I switch the language the output of the dump is false, the menu does not seem to exist.

EDIT: When using standard processwire API in my smarty template, the titles are fine.

{foreach $homepage->and($homepage->children) as $p}
                    <li {if $p->id == $page->id} class="active"{/if}><a href="{$p->url}">{$p->title}</a></li>
                {/foreach}

Share this post


Link to post
Share on other sites

I'm stumped to be honest. One, because I don't know much about ML setups. However, a number of people here seem to be using it fine in their ML installs. I have also tested in the default PW ML install and it worked fine. There were a few bugs reported but I fixed all of them. The default language there is English though. I don't know if that affects anything.

Btw, You say when you use standard PW API in your smarty template it works fine. I don't follow, is there some other 'non-standard' PW API that you've been using? 

Edit: Just realised my ML tests were done in a 2.5 core! Something might have changed in 2.7.3. I have tested and it doesn't work. I'll see if I can trace what's happening....I can't promise when though...I am afraid...especially given ML is a needle-haystack thing in my case :-)

Edited by kongondo

Share this post


Link to post
Share on other sites

My bad, i lie. I have just tested and it works fine in PW 2.7.3. Make sure you have the option 'defaultTitle' => 1, for this to work. Pass that in the array to renderMenu()

Edited by kongondo
more info

Share this post


Link to post
Share on other sites

Hi @kongondo,

I try to use this module with a multilanguage site with ProcessWire 3.0.15 (devns), but when I switch the language the menu does not show up. It only appears on the default language (german). Here is the code I used:

$menu = $modules->get('MarkupMenuBuilder');
    $options = array(
        'default_title' => 1,//0=show saved titles;1=show actual/current titles
    );

 $menu->render('mainmenu', $options));// @kongondo note this line is the problem...
The titles of the pages that are in the menu are translated in ProcessWire. 
Any suggestions what I can do to get it running?

OK, so I need a life or glasses or both! I missed that....

From the docs it says this about the method render()   :) [reason is in ML environment, MB will not always know what 'mainmenu' is (title varies per language)]

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. The second argument is an optional array and will fall back to defaults if no user configurations are passed to the method.

Share this post


Link to post
Share on other sites

@kongondo

Thank you for clarification. It works in my multilingual site if I use it with an ID:

$menu->render($pages->get(1126), $options)

But now another problem occurs. There are several empty A tags between my menu items with this configuration:

$menu = $modules->get('MarkupMenuBuilder');
        $defaultOptions = array(
            'wrapper_list_type' => 'div',//ul, ol, nav, div, etc.
            'list_type' => 'a',//li, a, span, etc.
            'menu_css_id' => '',
            'menu_css_class' => '',
            'current_css_id' => 'active',
            'divider' => '»',// e.g. Home >> About Us >> Leadership
            //prepend home page at the as topmost item even if it isn't part of the breadcrumb
            'prepend_home' => 1,//=> 0=no;1=yes
            'default_title' => 1,//0=show saved titles;1=show actual/current titles
            'include_children' => 0,//show 'natural' MB non-native descendant items as part of navigation
            'b_max_level' => 1,//how deep to fetch 'include_children'
        );
    
        $view->set('mainmenu', $menu->render($pages->get(1126), $defaultOptions));

$view-set is for assigning the menu to my smarty variable, in case you wonder. The output looks like

<div>
<a>
</a><a href="/">Start</a>

<a>
</a><a href="/de/termine/">Termine</a>

<a>
</a><a href="/de/produkte/">Produkte</a>

<a>
</a><a href="/de/haendler/">Händler</a>

<a>
</a><a href="/de/ueber-uns/">Über uns</a>

<a>
</a><a href="/de/news/">News</a>

</div>

Share this post


Link to post
Share on other sites

It's doing exactly what you've told it to do  :)  and it seems I need to update the example in the docs. The anchor tag (<a>) is always implied (it's a menu after all) so is always applied. That's why you are seeing double...the one always applied plus yours. What you need is to set an empty list_type

$menu = $modules->get('MarkupMenuBuilder');
  $defaultOptions = array(
    'wrapper_list_type' => 'div',//ul, ol, nav, div, etc.
    'list_type' => '',//li, a, span, etc. @note to self: need to remove this 'a' in docs 
    // etc..
   );

Share this post


Link to post
Share on other sites

Been getting questions on how to build complex/custom menus. Even with the ability to pass it custom options, some menus are a bit more complex than what Menu Builder offers out of the box. My answer to such questions has, to date, been get the JSON and use that to build your menu. Not very easy for some....but no more...thanks to @Beluga, @Peter and @Webrocker + others for the inspiration/challenges.
 
I've now added a method in MarkupMenuBuilder to make building custom complex menus a breeze. Don't get me wrong, you still have to know your foreach loops or even better grab one of the many recursive list/menu functions in the forums (or StackOverflow) and adapt it to your needs. Don't worry though, below, I provide a couple of complete code examples using recursive functions. For a 2-level deep menu, even a nested foreach would do. Going forward, this new method is what I recommend for building complex menus if using Menu Builder.
 
The new method is called getMenuItems($menu, $type = 2, $options = null) takes 3 arguments. Before I show you the cool things you can do with this method, let's get familiar with the arguments.
 
$menu: This is identical to the first argument in MarkupMenuBuilder's method render(): Use this argument to tell getMenuItems() the menu whose items you want returned. The argument takes a Page, id, title, name or array of menu items
 
$type: Whether to return a normal array or a Menu object (WireArray) of menu items
 
$options: Similar to render() method options but please note that only 3 options (from the list of those applicable to render()) apply to getMenuItems(). These are default_titledefault_class and current_class_leveldefault_class is applied to the  item's property $m['ccss_itemclass'].
 
Probably not many know that MarkupMenuBuilder ships with a tiny but useful internal class called Menu. MenuBuilder uses it internally to build Menu objects that are finally used to build menus. Menu objects are WireArrays. If $type == 2, this is what is returned.
 
Array vs WireArray
 
So, which  type of output should you return using getMenuItems()? Well, it depends on your needs. Personally, I'd go for the Menu object. Here's why:
 
Although you can still easily build menus by using getMenuItems() to return a normal PHP Array, it's not nearly as powerful as returning and using a WireArray Menu object instead. 
 
Whichever type of items you return using getMenuItems(), it means you can manipulate or apply logic before or within a recursive function (or foreach loop) to each of your menu items. For instance, show some parts of the menu only to users who are logged in, or get extra details from a field of the page represented by the menu item, add images to your menu items, etc. 
 
Grabbing the Menu object means you can easily add some runtime properties to each Menu object (i.e. each menu item). If you went with a normal array, of course, you can also manipulate it, but not as easily as working with an object. A Menu object also means you have access to the powerful WireArray methods (don't touch sort though!). For instance, $menuItems->find("parentID=$m->id"). With a Menu object, you also get to avoid annoying isset(var) that come with arrays :-).

 

Here are the properties that come with each Menu object. Use these to control your logic and output menu items values. In that block of code, to the left are the indices you'd get with a normal array. The values (to the right) are the Menu object properties.
 
Below are examples of building the W3Bits 'CSS-only responsive multi-level menu'  as illustrated in the tutorial by @Beluga. We use 3 different recursive functions to build the menu using items returned by getMenuItems(). I will eventually expound on and add the examples to my Menu Builder site. Meanwhile, here's a (very colourful) demo
 
Examples
 

@note: The CSS is the one by @Beluga in the tutorial linked to above.

@note: Clearer examples can be found in these gists.
 
First, we grab menu items and feed those to our recursive functions. 

$mb = $modules->get('MarkupMenuBuilder');// get Menu Builder
// get menu raw menu items. $menu can be a Page, an ID, a name, a title or an array
#$menu = $pages->get(1299);// pass a Page
#$menu = 1299;// pass an ID
#$menu = 'main';// pass a name
$jsonStr = $pages->get(1299)->menu_items;
$arrayFromJSON = json_decode($jsonStr, true);
#$menu = $arrayFromJSON;// pass an array
$menu = 'Main';// pass a title

/** grab menu items as WireArray with Menu objects **/
// for examples 1a, 2 and 3
$menuItems = $mb->getMenuItems($menu, 2, $options);// called with options and 2nd argument = 2 {return Menu (WireArray object)}
#$menuItems = $mb->getMenuItems($menu);// called without options; 2nd argument defaults to 2

/** grab menu items as Normal Array with Menu items **/
// only for example 1b below
menuItems2 = $mb->getMenuItems($menu, 1);// called without options; 2nd argument is 1 so return array

 
Example 1a: Using some recursive function and a Menu object

 

/**
* 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) {

  $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='main-menu cf'>\n";                            
              $first = 1;
            }                        
            else $out .= "\n<ul class='sub-menu'>\n";
        }

        $class = $m->isCurrent ? ' class="current"' : '';

        // a menu item
        $out .= '<li' . $class . '><a href="' . $m->url . '"' . $newtab . '>' . $m->title;                    
        // if menu item has children
        if ($m->isParent) {
          $out .= '<span class="drop-icon">▼</span>' .
              '<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($m->title) . '" onclick>▼</label>' .
          '</a>' .
          '<input type="checkbox" id="' . wire('sanitizer')->pageName($m->title) . '">';
        }
        
        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;

}

Example 1b: Using some recursive function and a Menu array 
 

/**
* Builds a nested list (menu items) of a single menu from an Array of menu items.
* 
* A recursive function to display nested list of menu items.
*
* @access private
* @param Int $parent ID of menu item.
* @param Array $menu Array of menu items to display.
* @param Int $first Helper variable to designate first menu item.
* @return string $out.
*
*/
function buildMenuFromArray($parent = 0, $menu, $first = 0) {

  $out = '';
  $has_child = false;
  
  foreach ($menu as $id => $m) {

    $parentID = isset($m['parent_id']) ? $m['parent_id'] : 0;
    $newtab = isset($m['newtab']) && $m['newtab'] ? " target='_blank'" : '';      
    // if this menu item is a parent; create the sub-items/child-menu-items
    if ($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='main-menu cf'>\n";              
              $first = 1;
            }            
            else $out .= "\n<ul class='sub-menu'>\n";
        }

        $class = isset($m['is_current']) && $m['is_current'] ? ' class="current"' : '';

        // a menu item
        $out .= '<li' . $class . '><a href="' . $m['url'] . '"' . $newtab . '>' . $m['title'];          
        // if menu item has children
        if (isset($m['is_parent']) && $m['is_parent']) {
          $out .= '<span class="drop-icon">▼</span>' .
              '<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($m['title']) . '" onclick>▼</label>' .
          '</a>' .
          '<input type="checkbox" id="' . wire('sanitizer')->pageName($m['title']) . '">';
        }
        
        else $out .= '</a>';         

        // call function again to generate nested list for sub-menu items belonging to this menu item. 
        $out .= buildMenuFromArray($id, $menu, $first);
        $out .= "</li>\n";

    }// end if parent
  
  }// end foreach

  if ($has_child === true) $out .= "</ul>\n";  

  return $out;

}

 
For example 1a and 1b we call the respective functions to output the menu 
 

<div id="content">    
  <nav id="mainMenu">
    <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'></span></label>
    <input id='tm' type='checkbox'>
<?php
  // build menu from Menu object (example 1a)
  echo buildMenuFromObject(0, $menuItems);
  // OR build menu from array (example 1b)
  #echo buildMenuFromArray(0, $menuItems2); 

?>
 </nav>
</div>

 
Example 2: Using a modified version of @mindplay.dk's recursive function 
 

/**
 * Recursively traverse and visit every child item in an array|object of Menu items.
 *
 * @param Menu item parent ID $parent to start traversal from.
 * @param callable $enter function to call upon visiting a child menu item.
 * @param callable|null $exit function to call after visiting a child menu item (and all of its children).
 * @param Menu Object|Array $menuItems to traverse.
 *
 * @see Modified From mindplay.dk https://processwire.com/talk/topic/110-recursive-navigation/#entry28241
 */
function visit($parent, $enter, $exit=null, $menuItems) {
  foreach ($menuItems as $m) {
    if ($m->parentID == $parent) {        
      call_user_func($enter, $m);
      if ($m->isParent) visit($m->id, $enter, $exit, $menuItems);
      if ($exit) call_user_func($exit, $m);
    }
  }
}

For example 2, we call the function (@note: a bit different from example 1 and 3) this way to output the menu 
 

<div id="content">
<nav id="mainMenu">
    <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'></span></label>
    <input id='tm' type='checkbox'>

<?php

echo "<ul class='main-menu cf'>";

visit(
  0// start from the top items
  ,
  // function $enter: <li> for a single menu item
  function($menuItem) {
    echo '<li><a href="' . $menuItem->url . '">' . $menuItem->title;
    if ($menuItem->isParent) {
      echo '<span class="drop-icon">▼</span>' .
        #'<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($menuItem->title) . '" onclick>▼</label>' .
        '<label title="Toggle Drop-down" class="drop-icon" for="sm' . $menuItem->id . '" onclick>▼</label>' .
        '</a>' .
        #'<input type="checkbox" id="' . wire('sanitizer')->pageName($menuItem->title) . '"><ul class="sub-menu">' . 
        '<input type="checkbox" id="sm' . $menuItem->id . '"><ul class="sub-menu">';
    }
    else echo '</a>';
  }// end function 1 ($enter)
  ,
  #function $exit: close menu item <li> and sub-menu <ul> tags
  function($menuItem) {
    if ($menuItem->isParent) echo '</ul>';
    echo '</li>';
  },
  $menuItems// the menu items (Menu objects in this example)
);

?>
 </nav>
</div>

Example 3: Using a modified version of @slkwrm's recursive function

 

/**
 * Recursively traverse and visit every child item in an array|object of Menu items.
 *
 * @param Menu Object|Array $menuItems to traverse.
 * @param Int $parent ID to start traversal from.
 * @param Int $depth Depth of sub-menus.
 * @param Int $first Helper variable to designate first menu item.
 * @see Modified From @slkwrm
 * @return string $out.    
 */
function treeMenu($menuItems, $parent, $depth = 1, $first = 0) {

  $depth -= 1;
  
  if ($first == 0){
    $out = "\n<ul class='main-menu cf'>";
    $first = 1;
  }            
  else $out = "\n<ul class='sub-menu'>";

  foreach($menuItems as $m) {
    if ($m->parentID == $parent) {
        $sub = '';
        $out .= "\n\t<li>\n\t\t<a href='" . $m->url . "'>" . $m->title;
        if($m->isParent && $depth > 0 ) {
          $sub = str_replace("\n", "\n\t\t", treeMenu($menuItems, $m->id, $depth, $first));
          $out .= '<span class="drop-icon">▼</span>' .
                '<label title="Toggle Drop-down" class="drop-icon" for="sm' . $m->id . '" onclick>▼</label>' .
              '</a>' .
              '<input type="checkbox" id="sm' . $m->id . '">' . 
              $sub . "\n\t";
        }
      
        else $out .= "</a>\n\t";

        $out .="\n\t</li>";
    }
  }// end foreach
  $out .= "\n</ul>";

  return $out;

}

For example 3, we call the function to output the menu

<div id="content">    
  <nav id="mainMenu">
    <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'></span></label>
    <input id='tm' type='checkbox'>
<?php
 //parameters: menuItems, menu item parent ID, depth, first (helper variable)
 echo treeMenu($menuItems, 0, 4);

?>
 </nav>
</div>
  • Like 8
  • Thanks 1

Share this post


Link to post
Share on other sites

Update: version 0.1.5

Changelog

  • Added new method getMenuItems() to MarkupMenuBuilder that greatly simplifies creation of custom complex menus. Read more about it in previous (long) post.
  • Like 3

Share this post


Link to post
Share on other sites

I guess it could now be possible to build menu markup for MenuBuilder with soma's MarkupSimpleNavigation module?

I'm not sure what the point of that would be (or whether it's even possible)?  :) ..MSN is brilliant if you want a menu that matches your page tree...MB mainly caters for the opposite need....

  • Like 1

Share this post


Link to post
Share on other sites

MSN is something to build markup with. I thought it was capable of getting custom WireArray in for building menu from instead of a page tree (as they are the same thing). If you got MSN set up as you need and you are familiar with it's API it is easier to use it for all menu generation instead of lerning how MenuBuilder does it. I am not saying MenuBuilder does it any worse though)) And of course you can always do it manually.

But MSN seems to be kind of a standard for PW menu markup generation and is probably more widely used than MenuBuilder. So as soon as I learned about MenuBuilder quite some time ago I was dreaming about using it just for the backend needs, and MSN for the markup. I just wrote that this use case is probably possible now. I'll write back as soon as I'll have a chance to check it out.

Thanks, kongondo!

Share this post


Link to post
Share on other sites

I don't know if MSN can use a WireArray to build menus. It certainly can take a PageArray and build a menu out of that. The key here is that MSN relies on true/natural PW child-parent relationships (unless something has changed that I don't know about) to create menus. So, $page->children will make sense to it. You won't get $page->children in MB...at least not in that original sense.

Share this post


Link to post
Share on other sites

Brilliant job kongondo. Thank you so much. 

  • Like 1

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 horst
      ---------------------------------------------------------------------------------------------------------------------------------
        when working with PW version 2.6+, please use Pim2, not Pim!
        read more here  on how to change from the older to the newer version in existing sites
      ---------------------------------------------------------------------------------------------------------------------------------
      PageImage Manipulator, API for version 1 & 2

      The Page Image Manipulator is a module that let you in a first place do ImageManipulations with your PageImages. - And in a second place there is the possibility to let it work on any imagefile that exists in your servers filesystem, regardless if it is a 'known PW-image'.

      The Page Image Manipulator is a Toolbox for Users and Moduledevelopers. It is written to be as close to the Core ImageSizer as possible. Besides the GD-filterfunctions it contains resize, crop, canvas, rotate, flip, sharpen, unsharpMask and 3 watermark methods.



      How does it work?

      You can enter the ImageManipulator by calling the method pim2Load(). After that you can chain together how many actions in what ever order you like. If your manipulation is finished, you call pimSave() to write the memory Image into a diskfile. pimSave() returns the PageImage-Object of the new written file so we are able to further use any known PW-image property or method. This way it integrates best into the ProcessWire flow.

      The three examples above put out the same visual result: a grayscale image with a width of 240px. Only the filenames will slightly differ.

      You have to define a name-prefix that you pass with the pimLoad() method. If the file with that prefix already exists, all operations are skipped and only the desired PageImage-Object gets returned by pimSave(). If you want to force recreation of the file, you can pass as second param a boolean true: pim2Load('myPrefix', true).

      You may also want to get rid of all variations at once? Than you can call $pageimage->pim2Load('myPrefix')->removePimVariations()!

      A complete list of all methods and actions are at the end of this post.
       
      You may also visit the post with tips & examples for users and module developers.


      How to Install
      Download the module Place the module files in /site/modules/PageImageManipulator/ In your admin, click Modules > Check for new modules Click "install" for PageImageManipulator Done! There are no configuration settings needed, just install and use it. Download    (version 0.2.0)
      get it from the Modules Directory History of origins

      http://processwire.com/talk/topic/3278-core-imagemanipulation/


      ----------------------------------------------------------------------------------------------------------


      Page Image Manipulator - Methods

      * pimLoad  or  pim2Load, depends on the version you use!

      pimLoad($prefix, $param2=optional, $param3=optional)
      param 1: $prefix - (string) = mandatory! param 2: mixed, $forceRecreation or $options param 3: mixed, $forceRecreation or $options return: pim - (class handle) $options - (array) default is empty, see the next method for a list of valid options! $forceRecreation - (bool) default is false It check if the desired image variation exists, if not or if forceRecreation is set to true, it prepares all settings to get ready for image manipulation
      -------------------------------------------------------------------

      * setOptions

      setOptions(array $options)
      param: $options - (array) default is empty return: pim - (class handle) Takes an array with any number valid options / properties and set them by replacing the class-defaults and / or the global config defaults optionally set in the site/config.php under imageSizerOptions or imageManipulatorOptions.

      valid options are:
      quality = 1 - 100 (integer) upscaling = true | false (boolean) cropping = true | false (boolean) autoRotation =true | false (boolean) sharpening = 'none' | 'soft' | 'medium' | 'strong' (string) bgcolor = (array) css rgb or css rgba, first three values are integer 0-255 and optional 4 value is float 0-1, - default is array(255,255,255,0) thumbnailColorizeCustom = (array) rgb with values for colorize, integer -255 - 255 (this can be used to set a custom color when working together with Thumbnails-Module)
        outputFormat = 'gif' | 'jpg' | 'png' (Attention: outputFormat cannot be specified as global option in $config->imageManipulatorOptions!) set {singleOption} ($value)
      For every valid option there is also a single method that you can call, like setQuality(90), setUpscaling(false), etc.
      -------------------------------------------------------------------

      * pimSave

      pimSave()
      return: PageImage-Object If a new image is hold in memory, it saves the current content into a diskfile, according to the settings of filename, imagetype, targetFilename and outputFormat. Returns a PageImage-Object!
      -------------------------------------------------------------------

      * release

      release()
      return: void (nothing) if you, for what ever reason, first load image into memory but than do not save it, you should call release() to do the dishes! 😉 If you use pimSave() to leave the ImageManipulator, release() is called automatically.
      -------------------------------------------------------------------

      * getOptions

      getOptions()
      return: associative array with all final option values example:
      ["autoRotation"] bool(true) ["upscaling"] bool(false) ["cropping"] bool(true) ["quality"] int(90) ["sharpening"] string(6) "medium" ["targetFilename"] string(96) "/htdocs/site/assets/files/1124/pim_prefix_filename.jpg" ["outputFormat"] string(3) "jpg" get {singleOption} ()
      For every valid option there is also a single method that you can call, like getQuality(), getUpscaling(), etc. See method setOptions for a list of valid options!
      -------------------------------------------------------------------

      * getImageInfo

      getImageInfo()
      return: associative array with useful informations of source imagefile example:
      ["type"] string(3) "jpg" ["imageType"] int(2) ["mimetype"] string(10) "image/jpeg" ["width"] int(500) ["height"] int(331) ["landscape"] bool(true) ["ratio"] float(1.5105740181269) ["bits"] int(8) ["channels"] int(3) ["colspace"] string(9) "DeviceRGB" -------------------------------------------------------------------

      * getPimVariations

      getPimVariations()
      return: array of Pageimages Collect all pimVariations of this Pageimage as a Pageimages array of Pageimage objects. All variations created by the core ImageSizer are not included in the collection.
      -------------------------------------------------------------------

      * removePimVariations

      removePimVariations()
      return: pim - (class handle) Removes all image variations that was created using the PIM, all variations that are created by the core ImageSizer are left untouched!
      -------------------------------------------------------------------
      * width

      width($dst_width, $sharpen_mode=null)
      param: $dst_width - (integer) param: $auto_sharpen - (boolean) default is true was deleted with version 0.0.8, - sorry for breaking compatibility param: $sharpen_mode - (string) possible: 'none' | 'soft' | 'medium' | 'strong', default is 'soft' return: pim - (class handle) Is a call to resize where you prioritize the width, like with pageimage. Additionally, after resizing, an automatic sharpening can be done with one of the three modes.
      -------------------------------------------------------------------

      * height

      height($dst_height, $sharpen_mode=null)
      param: $dst_height - (integer) param: $auto_sharpen - (boolean) default is true was deleted with version 0.0.8, - sorry for breaking compatibility param: $sharpen_mode - (string) possible: 'none' | 'soft' | 'medium' | 'strong', default is 'soft' return: pim - (class handle) Is a call to resize where you prioritize the height, like with pageimage. Additionally, after resizing, an automatic sharpening can be done with one of the three modes.
      -------------------------------------------------------------------

      * resize

      resize($dst_width=0, $dst_height=0, $sharpen_mode=null)
      param: $dst_width - (integer) default is 0 param: $dst_height - (integer) default is 0 param: $auto_sharpen - (boolean) default is true was deleted with version 0.0.8, - sorry for breaking compatibility param: $sharpen_mode - (string) possible: 'none' | 'soft' | 'medium' | 'strong', default is 'soft' return: pim - (class handle) Is a call to resize where you have to set width and / or height, like with pageimage size(). Additionally, after resizing, an automatic sharpening can be done with one of the three modes.
      -------------------------------------------------------------------

      * stepResize

      stepResize($dst_width=0, $dst_height=0)
      param: $dst_width - (integer) default is 0 param: $dst_height - (integer) default is 0 return: pim - (class handle) this performs a resizing but with multiple little steps, each step followed by a soft sharpening. That way you can get better result of sharpened images.
      -------------------------------------------------------------------

      * sharpen

      sharpen($mode='soft')
      param: $mode - (string) possible values 'none' | 'soft'| 'medium'| 'strong' return: pim - (class handle) Applys sharpening to the current memory image. You can call it with one of the three predefined pattern, or you can pass an array with your own pattern.
      -------------------------------------------------------------------

      * unsharpMask

      unsharpMask($amount, $radius, $threshold)
      param: $amount - (integer) 0 - 500, default is 100 param: $radius - (float) 0.1 - 50, default is 0.5 param: $threshold - (integer) 0 - 255, default is 3 return: pim - (class handle) Applys sharpening to the current memory image like the equal named filter in photoshop.
      Credit for the used unsharp mask algorithm goes to Torstein Hønsi who has created the function back in 2003.
      -------------------------------------------------------------------

      * smooth

      smooth($level=127)
      param: $level - (integer) 1 - 255, default is 127 return: pim - (class handle) Smooth is the opposite of sharpen. You can define how strong it should be applied, 1 is low and 255 is strong.
      -------------------------------------------------------------------

      * blur

      blur()
      return: pim - (class handle) Blur is like smooth, but cannot called with a value. It seems to be similar like a result of smooth with a value greater than 200.
      -------------------------------------------------------------------

      * crop

      crop($pos_x, $pos_y, $width, $height)
      param: $pos_x - (integer) start position left param: $pos_y - (integer) start position top param: $width - (integer) horizontal length of desired image part param: $height - (integer) vertical length of desired image part return: pim - (class handle) This method cut out a part of the memory image.
      -------------------------------------------------------------------

      * canvas

      canvas($width, $height, $bgcolor, $position, $padding)
      param: $width = mixed, associative array with options or integer, - mandatory! param: $height = integer, - mandatory if $width is integer! param: $bgcolor = array with rgb or rgba, - default is array(255, 255, 255, 0) param: $position = one out of north, northwest, center, etc, - default is center param: $padding = integer as percent of canvas length, - default is 0 return: pim - (class handle) This method creates a canvas according to the given width and height and position the memory image onto it.
      You can pass an associative options array as the first and only param. With it you have to set width and height and optionally any other valid param. Or you have to set at least width and height as integers.
      Hint: If you want use transparency with rgba and your sourceImage isn't of type PNG, you have to define 'png' as outputFormat with your initially options array or, for example, like this: $image->pimLoad('prefix')->setOutputFormat('png')->canvas(300, 300, array(210,233,238,0.5), 'c', 5)->pimSave()
      -------------------------------------------------------------------

      * flip

      flip($vertical=false)
      param: $vertical - (boolean) default is false return: pim - (class handle) This flips the image horizontal by default. (mirroring)
      If the boolean param is set to true, it flips the image vertical instead.
      -------------------------------------------------------------------

      * rotate

      rotate($degree, $backgroundColor=127)
      param: $degree - (integer) valid is -360 0 360 param: $backgroundColor - (integer) valid is 0 - 255, default is 127 return: pim - (class handle) This rotates the image. Positive values for degree rotates clockwise, negative values counter clockwise. If you use other values than 90, 180, 270, the additional space gets filled with the defined background color.
      -------------------------------------------------------------------

      * brightness

      brightness($level)
      param: $level - (integer) -255 0 255 return: pim - (class handle) You can adjust brightness by defining a value between -255 and +255. Zero lets it unchanged, negative values results in darker images and positive values in lighter images.
      -------------------------------------------------------------------

      * contrast

      contrast($level)
      param: $level - (integer) -255 0 255 return: pim - (class handle) You can adjust contrast by defining a value between -255 and +255. Zero lets it unchanged, negative values results in lesser contrast and positive values in higher contrast.
      -------------------------------------------------------------------

      * grayscale

      grayscale()
      return: pim - (class handle) Turns an image into grayscale. Remove all colors.
      -------------------------------------------------------------------

      * sepia

      sepia()
      return: pim - (class handle) Turns the memory image into a colorized grayscale image with a predefined rgb-color that is known as "sepia".
      -------------------------------------------------------------------

      * colorize

      colorize($anyColor)
      param: $anyColor - (array) like css rgb or css rgba - but with values for rgb -255 - +255,  - value for alpha is float 0 - 1, 0 = transparent  1 = opaque return: pim - (class handle) Here you can adjust each of the RGB colors and optionally the alpha channel. Zero lets the channel unchanged whereas negative values results in lesser / darker parts of that channel and higher values in stronger saturisation of that channel.
      -------------------------------------------------------------------

      * negate

      negate()
      return: pim - (class handle) Turns an image into a "negative".
      -------------------------------------------------------------------

      * pixelate

      pixelate($blockSize=3)
      param: $blockSize - (integer) 1 - ??, default is 3 return: pim - (class handle) This apply the well known PixelLook to the memory image. It is stronger with higher values for blockSize.
      -------------------------------------------------------------------

      * emboss

      emboss()
      return: pim - (class handle) This apply the emboss effect to the memory image.
      -------------------------------------------------------------------

      * edgedetect

      edgedetect()
      return: pim - (class handle) This apply the edge-detect effect to the memory image.
      -------------------------------------------------------------------

      * getMemoryImage

      getMemoryImage()
      return: memoryimage - (GD-Resource) If you want apply something that isn't available with that class, you simply can check out the current memory image and apply your image - voodoo - stuff
      -------------------------------------------------------------------

      * setMemoryImage

      setMemoryImage($memoryImage)
      param: $memoryImage - (GD-Resource) return: pim - (class handle) If you are ready with your own image stuff, you can check in the memory image for further use with the class.
      -------------------------------------------------------------------

      * watermarkLogo

      watermarkLogo($pngAlphaImage, $position='center', $padding=2)
      param: $pngAlphaImage - mixed [systemfilepath or PageImageObject] to/from a PNG with transparency param: $position - (string) is one out of: N, E, S, W, C, NE, SE, SW, NW,
      - or: north, east, south, west, center, northeast, southeast, southwest, northwest
      default is 'center' param: $padding - (integer) 0 - 25, default is 5, padding to the borders in percent of the images length! return: pim - (class handle) You can pass a transparent image with its filename or as a PageImage to the method. If the watermark is bigger than the destination-image, it gets shrinked to fit into the targetimage. If it is a small watermark image you can define the position of it:
      NW - N - NE | | | W - C - E | | | SW - S - SE  
      The easiest and best way I have discovered to apply a big transparency watermark to an image is as follows:
      create a square transparent png image of e.g. 2000 x 2000 px, place your mark into the center with enough (percent) of space to the borders. You can see an example here! The $pngAlphaImage get centered and shrinked to fit into the memory image. No hassle with what width and / or height should I use?, how many space for the borders?, etc.
      -------------------------------------------------------------------

      * watermarkLogoTiled

      watermarkLogoTiled($pngAlphaImage)
      param: $pngAlphaImage - mixed [systemfilepath or PageImageObject] to/from a PNG with transparency return: pim - (class handle) Here you have to pass a tile png with transparency (e.g. something between 150-300 px?) to your bigger images. It got repeated all over the memory image starting at the top left corner.
      -------------------------------------------------------------------

      * watermarkText

      watermarkText($text, $size=10, $position='center', $padding=2, $opacity=50, $trueTypeFont=null)
      param: $text - (string) the text that you want to display on the image param: $size - (integer) 1 - 100, unit = points, good value seems to be around 10 to 15 param: $position - (string) is one out of: N, E, S, W, C, NE, SE, SW, NW,
      - or: north, east, south, west, center, northeast, southeast, southwest, northwest
      default is 'center' param: $padding - (integer) 0 - 25, default is 2, padding to the borders in percent of the images length! param: $opacity- (integer) 1 - 100, default is 50 param: $trueTypeFont - (string) systemfilepath to a TrueTypeFont, default is freesansbold.ttf (is GPL & comes with the module) return: pim - (class handle) Here you can display (dynamic) text with transparency over the memory image. You have to define your text, and optionally size, position, padding, opacity for it. And if you don't like the default font, freesansbold, you have to point to a TrueTypeFont-File of your choice.
      Please have a look to example output: http://processwire.com/talk/topic/4264-release-page-image-manipulator/page-2#entry41989
      -------------------------------------------------------------------





      PageImage Manipulator - Example Output


    • By d'Hinnisdaël
      Format Datetime fields as Carbon instances.
      You can find the latest release and the complete readme on Github.
      Installation
      composer require daun/datetime-carbon-format Usage
      All Datetime fields will now be formatted as Carbon instances instead of strings. Some examples:
      // $page->date is a Datetime field // Output format: j/n/Y echo $page->date; // 20/10/2020 echo $page->date->add('7 days'); // 27/10/2020 echo $page->date->format('l, F j'); // Monday, October 20 echo $page->date->year; // 2020 echo $page->date->diffForHumans(); // 28 minutes ago Frontend only
      The ProcessWire admin seems to expect datetime fields to be strings. This module will only return Carbon instances on frontend page views.
      Date output format
      When casting a Carbon instance to a string (usually when outputting the field in a template), the field's date output format will be respected.
      Links
      GitHub • Readme • Carbon docs
       
       
      PS. I remember reading about a Carbon module in a recent newsletter, but couldn't find it anywhere. Was that you, @bernhard?
    • By MoritzLost
      TrelloWire
      This is a module that allows you to automatically create Trello cards for ProcessWire pages and update them when the pages are updated. This allows you to setup connected workflows. Card properties and change handling behaviour can be customized through the extensive module configuration. Every action the module performs is hookable, so you can modify when and how cards are created as much as you need to. The module also contains an API-component that makes it easy to make requests to the Trello API and build your own connected ProcessWire-Trello workflows.
      Warning: This module requires ProcessWire 3.0.167 which is above the current stable master release at the moment.
      Features
      All the things the module can do for you without any custom code: Create a new card on Trello whenever a page is added or published (you can select applicable templates). Configure the target board, target list, name and description for new cards. Add default labels and checklists to the card. Update the card whenever the page is updated (optional). When the status of the card changes (published / unpublished, hidden / unhidden, trashed / restored or deleted), move the card to a different list or archive or delete it (configurable). You can extend this through hooks in many ways: Modifiy when and how cards are created. Modify the card properties (Target board & list, title, description, et c.) before they are sent to Trello. Create your own workflows by utilizing an API helper class with many convenient utility methods to access the Trello API directly. Feedback & Future Plans
      Let me know what you think! In particular:
      If you find any bugs report them here or on Github, I'll try to fix them. This module was born out of a use-case for a client project where we manage new form submissions through Trello. I'm not sure how many use-cases there are for this module. If you do use it, tell me about it! The Trello API is pretty extensive, I'll try to add some more helper methods to the TrelloWireApi class (let me know if you need anything in particular). I'll think about how the module can support different workflows that include Twig – talk to me if you have a use-case! Next steps could be a dashboard to manage pages that are connected to a Trello card, or a new section in the settings tab to manage the Trello connection. But it depends on whether there is any interest in this 🙂 Links
      Repository on Github Complete module documentation (getting started, configuration & API documentation) TrelloWire in the modules directory Module configuration

×
×
  • Create New...