Jump to content

MarkupSimpleNavigation


Soma

Recommended Posts

Next little tutorial on this really great module...

Getting a Footermenu stripped from the mainmenu and output in a footermenu

1. Setup Pagefield for your /settings/ or /tools/ page

This solution could be set by the user direct via a simple pagefield to select normal contentpages that a normaly in the mainmenu...but this items should stay not there and render somewhere else...

post-2327-0-42569000-1442412709_thumb.jp

2. Strip the choosen pages from the mainmenu

//get the pagefield content
$footerMenu = $settings->footer_menu;

//just the needed option listed - other options like needed for your menu
$options = array(
       'selector' => 'id!='.$footerMenu.'',    // define custom PW selector
);

3. Output the pagefield items

post-2327-0-41513000-1442412792_thumb.jp

<?php //in my example i am in the _main.php template and render some footermenu
if ($settings->footer_menu) { //check for the pagefield
    echo '<div class="eight columns">';
    foreach ($settings->footer_menu as $item) {
        if (!$item->is('hidden') || $item->is('unpublished')) { //check for hidden/unpublished pages!!
	    echo '<a href="'.$item->url.'" class="button sendbtn btnSend">'.$item->title.'</a>';
	}
    }
    echo '</div>';
}
?>

hope this is helpful...have fun.

I don't have a blog and i am a fan of keeping things together....so don't bother if i'm posting such things here and write me if such usecases are not helpful or nonsense...... ;)

Best regards mr-fan

  • Like 2
Link to comment
Share on other sites

Is it possible to use the "selector" option to choose menu items based on parent?

I tried...

"selector" => "parent=1020"

...and...

"selector" => "parent=/my-page/"

...but neither of these worked.

I know I can do this by setting a PageArray as the root object but I'm trying to understand why I can't do this with the selector option.

Link to comment
Share on other sites

No it's not possible, it iterates the tree structure as is. "parent -> childrens -> childrens".

You can only set the top root items per a PageArray. Form there these are iterated down the tree. The selector only is used to filter the children of the current nodes.

Link to comment
Share on other sites

Next little tutorial on this really great module...

Getting a Footermenu stripped from the mainmenu and output in a footermenu

1. Setup Pagefield for your /settings/ or /tools/ page

This solution could be set by the user direct via a simple pagefield to select normal contentpages that a normaly in the mainmenu...but this items should stay not there and render somewhere else...

attachicon.giffootermenu.jpg

2. Strip the choosen pages from the mainmenu

//get the pagefield content
$footerMenu = $settings->footer_menu;

//just the needed option listed - other options like needed for your menu
$options = array(
       'selector' => 'id!='.$footerMenu.'',    // define custom PW selector
);

3. Output the pagefield items

attachicon.giffootermenusorting.jpg

<?php //in my example i am in the _main.php template and render some footermenu
if ($settings->footer_menu) { //check for the pagefield
    echo '<div class="eight columns">';
    foreach ($settings->footer_menu as $item) {
        if (!$item->is('hidden') || $item->is('unpublished')) { //check for hidden/unpublished pages!!
	    echo '<a href="'.$item->url.'" class="button sendbtn btnSend">'.$item->title.'</a>';
	}
    }
    echo '</div>';
}
?>

hope this is helpful...have fun.

I don't have a blog and i am a fan of keeping things together....so don't bother if i'm posting such things here and write me if such usecases are not helpful or nonsense...... ;)

Best regards mr-fan

There's a tutorial board here in the forums where you would post such examples. I don't think it helps much in here.

Link to comment
Share on other sites

There's a tutorial board here in the forums where you would post such examples. I don't think it helps much in here.

Ok if i've the time i collect my snippets to a "Tipps&Tricks with MarkupSimpleNavigation" topic - to get things connected.

For myself - i always read modulethreat completly if i'm using them to get the best start or knowlegde about the used addon...Read the fucking Manual....is not a option it is a obligation if you are new to a cms/module/technique....;)

But i will follow your advice since it better fits as tutorials than tracking issues or getting help.

Best regards and thank you for feedback mr-fan

Link to comment
Share on other sites

  • 1 month later...

Markup Simple Navigation Module

While there was a lot of people asking how to make navigation, and there were many examples around already (apeisa, ryan...) I took the chance to sit down 2-3 hours to make a simple navigation module. It has even some options you can control some aspects of the output.

Installation:

1. Put this module's folder "MarkupSimpleNavigation" into your /site/modules folder.

2. Go to your module Install page and click "Check for new modules". It will appear under the section Markup. Click "install" button. Done.

Technically you don't even need to install it, after the first load call ( $modules->get("MarkupSimpleNavigation") ) it will install automaticly on first request if it isn't already. But it feels better. However, it will not be "autoloaded" by Processwire unless you load it in one of your php templates.

Documentation:

https://github.com/somatonic/MarkupSimpleNavigation/blob/master/README.md

Modules Repository processwire.com

mods.pw/u

Download on github

https://github.com/somatonic/MarkupSimpleNavigation

Advanced example with hooks

creating a Bootstrap 2.3.2 Multilevel Navbar

https://gist.github.com/somatonic/6258081

I use hooks to manipulate certain attributes and classes to li's and anchors. If you understand the concept you can do a lot with this Module.

could i put the "creating a Bootstrap 2.3.2 Multilevel Navbar" code in the _init.php to run ?

Link to comment
Share on other sites

Hi Soma,

I need to use plain PHP pages ("/foo/bar.php") to a website powered by ProcessWire. How can I add this in Markup Simple Navigation?

Sample structure that shows the mix of Processwire pages and PHP pages in use:

  • Products
    • Product 1
    • Product 2
    • Product 3
    • Request quote <- Quote form in plain PHP.
  • References
  • About us
Link to comment
Share on other sites

Wanted to ask the same.

Only way I see is use a page with a text field to enter a path to a php file. Then use that field as in the url tag in the item template. I.e. href='{pathphp|url}'

Link to comment
Share on other sites

@Mike Rockett & Soma: The reason for processing the form outside PW is that it's part of a 3rd party booking system using an external database.

I have the following enhancement request for the module: "It shall be possible to include plain PHP pages ("/foo/bar.php") from third party plug-ins and the like to MarkupSimpleNavigation. Suggested solution is to allow adding in-memory pages to the navigation entries on the fly. The purpose of adding in-memory pages is to place the 3rd party page in PWs Page structure. Something along these lines:

$p = new Page();
$p->setOutputFormatting(false);
$p->parent = $pages->get("/MyParentPage");
$p->template = "SomeTemplate";
$p->title = "External page";
$p->name = "external_page";
// Note I do not use $p->save(), so it's a pseudo page that exists in memory only.
// Add the page to $entries somehow [...] -> $entries = $pages->get("/")->navigation_entries; ....
$entries = $pages->get("/")->navigation_entries; // Load entries (including our new page)
echo $treeMenu->render(null, null, $entries);

(Perhaps this is already possible without making changes to the module?)

Right now, I will go ahead and 1) make a unique template for the form that "include()" the form from a PHP file, 2) add a PW page for the form and 3) repeat this process for all relevant files (4 times in total per site using the booking system). I can then output a link and title to the page using MarkupSimpleNavigation. (I have done this before, it's a bit cumbersome but it will work.)

Link to comment
Share on other sites

While it would be possible to inject in memory pages, I don't want to go that route for various reasons.

What I do is add a dummy page as you mention. Then add a field "exturl" to the template. Then enter the url in that field like "/path/to/file.php".

In the navigation code you then use "exturl" in the item_tpl:

$options = array("item_tpl" => "<a href='{exturl|url}>{title}</a>');
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I have problems with outputting the whole Menu Tree  up to the parent page Product when in 3rd level of a submenu.

The structure is

Home

  Products

      product 1

      product 2

         Item 1

         Item 2

         Item 4

      product 3

My menu looks like this

$leftNav = $modules->get("MarkupSimpleNavigation");

$leftNavOptions = array(
	'max_levels' => 3,
	'collapsed' => true,
	'show_root' => false,
	'levels' => true,
	'outer_tpl' => '<ul id="leftNavOuter" class="noPrint">||</ul>',
	'firstlast' => true
);

$root = $page->parents->count == 1 ? $page : $page->parent;
echo $leftNav->render($leftNavOptions, $page, $root);

that works perfect well until you navigate into the 3rd Level, then all levels above disapear and you see only the items level

Is there a way to output all three levels when in 3rd level?

Your help is much appreciated.

Link to comment
Share on other sites

that works perfect well until you navigate into the 3rd Level, then all levels above disapear and you see only the items level

I think your problem comes from this:

$root = $page->parents->count == 1 ? $page : $page->parent;

For the first two levels $root is "Products", but on the third level $root is "product 2" or whatever level 2 parent you are in. So you only see children of "product 2".

I think this will do what you want:

$root = $page->rootParent;
Link to comment
Share on other sites

  • 2 weeks later...

Hello all,

I have two questions:

First:

using MSN Module ... is it possible to have "unlinked" items  in the menu?.
I have several pages that serve as headlines to structure the content better. They have a seprate template (menu-ueberschrift) and they should not be clickable ... just be there as plain text. These Items have children. I want an uncollapsed menu..

Second question:

Goes into the same direction: I would like to have active pages without links, too. I think there is no need for links  for a page I'm currently viewing.

Hopefully someone can help, as I'm stuck here.

Link to comment
Share on other sites

Solved it myself ...

Finally managed to set up hooks:

function myItemString(HookEvent $event) {
    $child = $event->arguments('page'); // current rendered child page
    // any logic with $child possible here
    
    /**
     * Überschriften
     */
    if ($child->template->name == 'menue-ueberschrift') {
        $event->return = "<span> $child->title</span>";
    };

    /**
     * active
     */
    if ($child->template->name == 'standard') {
        if ($child->id == wire('page')->id) {
            $event->return = "<span> $child->title</span>";

        }
    };
}

// setup the hook after on ___getItemString($class, $page) method
$nav->addHookAfter('getItemString', null, 'myItemString');
/* Render Navigation Markup adding options, too---------------- */
echo $nav->render()

Seems to work so I guess it's ok.

And I've learned something new :-)

Cheers Hanna

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Ok,

I am having some issues with this menu (will be in bootstrap).

I currently have:

		<?php
			$nav = $modules->get("MarkupSimpleNavigation");

	 function hookGetListClass(HookEvent $event){
	    $child = $event->arguments('page'); // current rendered child page
	    $class = $event->arguments('class'); // the class string already present
			$options = array(
				'has_children_class' => 'dropdown',
				'outer_tpl' => '<ul class="nav">||</ul>',
				'inner_tpl' => '<ul class="dropdown-menu">||</ul>'
			);


	     // any check on that child to set your custom class
	     if($child->id == 1001){
	         $event->return .= " inner"; // add your custom class to the existing
	     }
	 }

	 // setup the hook after on ___getListClass($class, $page) method
	 $nav->addHookAfter('getListClass', null, 'hookGetListClass');
	 echo $nav->render($options);
	 ?>

However, the nav doesnt seem to be taking the options, and is instead using the "has_children" class. I saw a post almost exactly like this, but couldnt get the outcome. The inner ul should have a class of "dropdown".

Link to comment
Share on other sites

Hey guys,

I love this plugin. It works almost perfect for me. But I have a little question. I want that the parents don´t have a link.

This is my markup now:
<nav>
               
        <a href="<?=$config->urls->root; ?>" id="home">Von der Berkelaue</a>
       
        <?php 
            $treeMenu = $modules->get("MarkupSimpleNavigation"); // Modul laden   

        
            $options = array(
                'max_levels' => 2,
                'show_root' => true,
                'outer_tpl' => '<ul id="menu">||</ul>',
                'inner_tpl' => '<ul>||</ul>',
                'list_tpl' => '<li%s>||</li>',
                'item_tpl' => '<a href="{url}">{title}</a>',
                'item_current_tpl' => '<a href="{url}" class="active">{title}</a>',
                'debug' => true,
                'selector' => 'template!=aktuelles-eintrag, has_parent!=/galerie/',
            );
            echo $treeMenu->render($options); // Navigation rendern
        ?>
    </nav>

And this is my output:

<ul id="menu">
    <li class="current"><a href="/" class="active">Startseite</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/aktuelles/">Aktuelles</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li class="has_children"><a href="/uber-uns/">Über uns</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
        <ul>
            <li><a href="/uber-uns/familie/">Familie</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/uber-uns/unsere-hunde/">Unsere Landseer</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
        </ul>
    </li>
    <li><a href="/wurfplanung/">Wurfplanung</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li class="has_children"><a href="/wurfe/">Würfe</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
        <ul>
            <li><a href="/wurfe/wurfplanung/">A-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/b-wurf/">B-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/c-wurf/">C-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/d-wurf/">D-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/e-wurf/">E-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/f-wurf/">F-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/g-wurf/">G-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
        </ul>
    </li>
    <li><a href="/galerie/">Galerie</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/gastebuch/">Gästebuch</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/links/">Links</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/kontakt/">Kontakt</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
</ul>
<!-- [MarkupSimpleNavigation Rendertime: 0.0366] -->
</nav>

And it should look like this:

<ul id="menu">
    <li class="current"><a href="/" class="active">Startseite</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/aktuelles/">Aktuelles</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li class="has_children"><a href="#">Über uns</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
        <ul>
            <li><a href="/uber-uns/familie/">Familie</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/uber-uns/unsere-hunde/">Unsere Landseer</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
        </ul>
    </li>
    <li><a href="/wurfplanung/">Wurfplanung</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li class="has_children"><a href="#">Würfe</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
        <ul>
            <li><a href="/wurfe/wurfplanung/">A-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/b-wurf/">B-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/c-wurf/">C-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/d-wurf/">D-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/e-wurf/">E-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/f-wurf/">F-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
            <li><a href="/wurfe/g-wurf/">G-Wurf</a>
                <!-- [Selector Level2: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
            </li>
        </ul>
    </li>
    <li><a href="/galerie/">Galerie</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/gastebuch/">Gästebuch</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/links/">Links</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
    <li><a href="/kontakt/">Kontakt</a>
        <!-- [Selector Level1: template!=aktuelles-eintrag, has_parent!=/galerie/] -->
    </li>
</ul>
<!-- [MarkupSimpleNavigation Rendertime: 0.0366] -->
</nav>

I hope you understand my problem. My english isn´t very good :D

Thanks, Jannis

Link to comment
Share on other sites

Hi Jannis,

Is  that you want this

<li class="has_children"><a href="#">Über uns</a>

appear like a headline ? with no link?

I think it would be a good idea to give those 'headlines' their own template like 'ueberschrift' or so.

Then you could proceed similar to what I posted here using a hook.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

i am using this Module for quit a while with great joy. Easy to implement and very flexible.

Right now i wonder if something like this is possible by using just the module options without hooking the core: I have a 2-level menu with several parents and relevant child pages. On last parent the child array is (should) populated from a variable ($items), which collects only (child) pages with dedicated page view permission.

So i fiddle around with the "selector_levelN" option. First try:

$options = array(
  "levels" => true,
  "max_levels" => 2,
  "selector_level2" => "id=$items"
);

This gives me the expected result in level2 on the last child tree, but fails of course because the selector ("id="$items") returns nothing on all other parent/child levels. What i would need is some condition like (Tried this and other notations, no luck):

$options = array(
...
"selector_level2" => (parent=<id>) ? "id=$items" : ""
);

In words. If the parent page has a dedicated ID (here: the parent page which holds all permission controlled (child) pages), populate the "selector_level2" option with predefined pages ($items), otherwise don't constrain the collecting for level 2.

Probably this is the nutshell: Are condition possible/allowed in module option selector values?

cheers and thanks

felic

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...