Jump to content

MarkupSimpleNavigation


Soma

Recommended Posts

  • 2 weeks later...
$features = $pages->find("bfd_events_people_id%=$page->id, sort=bfd_year");

That kind of selector could yield wrong results. If you are finding by ID, then you should really be using page references, not text fields. If you were searching for id "123" the selector above would also match "2123", "1234", "9912399", etc. That's why it could be problematic. If for some reason you needed to search this way (using text fields rather than page references) you'd be better off using the "~=" operator, which matches whole words and should provide more accurate results for that scenario. But this is a situation that really calls for page references (FieldtypePage). 

Link to comment
Share on other sites

I would like to have a navigation list of related pages (events) on a certain page.

find("template=bfd_events, bfd_events_people_id%=$page->id")

Where do I put the find option? In $rootPage = $pages->get("/events/"); or in options -> 'selector' => '',?

This module doesn't work like this. You can't specify "root" pages to build the menu using a find. It works from a "parent" its way down the tree. There's only a selector option to specify what pages would be included/excluded. For simple lists you're better off creating your own code which is very simple in PW.

Link to comment
Share on other sites

How exacly selector_field works ?
i made template called list in it there is a field (checkbox) called dont_show
if this checkbox is checked i dont want to show children of this template. how can i do this  ?

Ty




			
		
Link to comment
Share on other sites

How exacly selector_field works ?

i made template called list in it there is a field (checkbox) called dont_show

if this checkbox is checked i dont want to show children of this template. how can i do this  ?

selector_field is to define what field or property (runtime) you want to use to specify the selector.

Default is "nav_selector" so this would translate to:

$page->nav_selector = "yourselector"

a)

This can be a field on a page, create a text field named "nav_selector" and add it to you template. Now you can enter a selector on pages using this template and the module will take that if it's defined.

b)

Or you set it on the fly before you render the navigation. Then you don't need to have a text field "nav_selector" added to your templates at all. You just set the property with code.

This could be simply a little code you run to set the selector to those pages, in your case those that have the checkbox:

foreach($pages->find("dont_show=1") as $p) $p->nav_selector = "yourselector";

In your case I'm not sure what would be the best way to not render children of that page. Maybe something like this:

foreach($pages->find("dont_show=1") as $p) $p->nav_selector = "parent!=$p->id";

c)

Alternatively this could also work using the options "selector".

"selector" => "parent.dont_show=0";

but not sure really this is possible at all :)

  • Like 1
Link to comment
Share on other sites

any reason my

foreach($pages->find("dont_show=1") as $p) {
    $p->nav_selector = "parent!=$p->id";
}

shows only one result

parent!=1034 

where there should be id 1015 also??

c)


Alternatively this could also work using the options "selector".


"selector" => "parent.dont_show=0";

ye this is not working ;/

i can just choose template as a selector but this checkbox is so nice :P



Link to comment
Share on other sites

I don't really get what you trying to di anymore. Do you want to not show the page in nav that have checkbox checked or only its children? There is no thing like !children.subfield=value in PW, it's not a valid selector.

Link to comment
Share on other sites

i dont want to show a children of this template, and honestly it works.

here is a full code i use for my nav.
u can also view the page here: midven.avenueagency.eu
 

Page is still in building process

<?php

	$rootPage = $pages->get("/");
    $treeMenu = $modules->get("MarkupSimpleNavigation"); // load the module
    $options = array(
		'parent_class' => 'parent',
		'current_class' => 'current',
		'has_children_class' => 'has_children',
		'levels' => true,
		'levels_prefix' => 'level-',
		'max_levels' => 2,
		'firstlast' => false,
		'collapsed' => false,
		'show_root' => true,
		'selector' => '!children.dont_show=1',
		'outer_tpl' => '||',
		'inner_tpl' => '<ul>||</ul>',
		'list_tpl' => '<li%s>||</li>',
		'list_field_class' => '',
		'item_tpl' => '<a href="{url}"><span>{title}</span></a>',
		'item_current_tpl' => '<a href="{url}"><span>{title}</span></a>',
		'item_root_tpl' => '<a href="{url}"><span>{title}</span></a>',
		'xtemplates' => '',
		'xitem_tpl' => '<span>{title}</span>',
		'xitem_current_tpl' => '<span>{title}</span>'
		);
    function hookGetListClass(HookEvent $event){
	    $child = $event->arguments('page'); // current rendered child page
	    $class = $event->arguments('class'); // the class string already present

	    // any API check on that child
        $event->return .= " id_".$child->id; // add your custom class to the existing
	}
	$treeMenu->addHookAfter('getListClass', null, 'hookGetListClass');
?>

<nav id="main-nav">
	<div class="header"><a href="#side-nav" class="dropDown">Menu</a></div>
	<div class="wrap" data-target="#side-nav">
		<ul>
			<?php echo $treeMenu->render($options, $page, $rootPage); ?>
		</ul>
	</div>
</nav>

Link to comment
Share on other sites

I just update PW to dev version and it stopped working ;(

and im still with the problem. I used this method to not show children of thoes parents:

'selector' => '!parent=1034|1015',

but there is page id 1090 within 1015 which i need exceptionally show. is there some method to overrule selector ?
 

Link to comment
Share on other sites

Sorry I'm still not sure what you want to archive as everytime it's a little different. I'm a bit lost and can't say anything without knowing exactly and maybe try myself. I like to help you but can't. There seem to be multiple ways to archive what you want.

I'm reading your posts again and kinda lost what the current state is. As I showed you could add a selector per page using the find:

foreach($pages->find("dont_show=1") as $p) {
    $p->nav_selector = "parent!=$p->id";
}

This should work and I don't know why it does not in your case. But after all I haven't tried so I can't really say 100%.

Maybe you can tell me again if I understand correctly: You want to exclude children of a certain parent? Right? 

What I can say for sure is:

"!parent=1034|1015" just isn't a valid selector it would have to be "parent!=1034|1015".

But if you do this you can't overwrite it for a certain children to still show, as it will never get to it. Does that make sense? :)

Maybe you can draw me a picture?

Edit: corrected typo... oh dear.

Link to comment
Share on other sites

I pushed an update to 1.2.2, I seem to have forgot to commit earlier.

It fixes an issue with the new "selector_level[n]" option introduced previously. It wasn't working quite correctly and after lot of trying I found what was going on which was quite tricky. I'm not sure anyone was using this feature already so it might not make any difference, just wanted to make a note.

The additional selector option can be used to define selector for different levels like so:

"selector_level1" => "template!=news",

"selector_level2" => "id!=1033|1239",

...

Link to comment
Share on other sites

  • 3 weeks later...

Hello,

I have a litte problem in the understanding how the module is working.

When I just need a plain tree-menu this is the most easy way to accomplish the task. But I have two separate navigations that belong together.

For example:

 

First Navigation is a horizontal list with links of the 1st level.

 

Second Navigation is a vertical list with links of the 2nd+ level.

My problem is now, that I have no idea how I can build this with the module. How can I tell the second navigation to render just the 2nd level and more when the equivalent first item is active?!

Best regards and thanks,

Martin

Link to comment
Share on other sites

Martin, welcome to PW!

If I understand correctly, you want the horizontal menu to show children of the home page (plus maybe the home page itself), and the vertical menu to show children of the current page?

I would be inclined just to use some simple php - 

For the horizontal menu something like this, styled in CSS as a horizontal menu...

<ul>
<?php
$home = $pages->get('/');
echo "<li><a href='$home->url'>$home->title</a>";
foreach($home->children() as $child){
  echo "<li><a href='$child->url'>$child->title</a></li>";
}
?>
</ul>

And then for the vertical menu, something very similar...

<ul>
<?php
foreach($page->children() as $child){
  echo "<li><a href='$child->url'>$child->title</a></li>";
}
?>
</ul>

NB All written in browser, so untested, but should work  :)

Link to comment
Share on other sites

With MSN this could look like this:

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

// topnav
$current = $page->rootParent(); // current root page
echo $nav->render(array(
    'max_levels' => 1
  ), $current);

// subnav
echo $nav->render(array(
    'max_levels' => 1
  ), $page, $current);
 
  • Like 1
Link to comment
Share on other sites

Thanks DaveP and thanks Soma!

The MSN version is working fine! Thanks for that.

I built the plain PHP version by myself, but the problem was, that it changed navigation points when it gets deeper in hierarchy. Maybe I had another error in my code but it didn't worked the way I wanted it to... :)

Thanks for the fast response!

Link to comment
Share on other sites

  • 2 weeks later...

Thanks Soma for this example : https://gist.github.com/somatonic/6258081

Testing it on a multi language site with a bootstrap 3 menu, how can I hide the <b class="caret"></b> in the homepage link and make it href link work just for that parent? Note: I have another parent that will open the dropdown children's menu. 

 

After Soma's hooks setup to render the $navMarkup I have:

$navMarkup = $nav->render(
    array(
      'levels' => true,
      'show_root' => true,
      'selector'=>"limit=6, start=0",
      'max_levels' => 4,
      'current_class' => 'active',
      'has_children_class' => 'dropdown',
      'outer_tpl' => '<ul class="nav navbar-nav">||</ul>',
      'inner_tpl' => '<ul class="dropdown-menu">||</ul>',
        )
    );

Another thing, having this as a menu structure:

homepage

-about

-services

  -service one

  -service two

If I select the service one or two links in the services parent page, the children's class is "active" can I set the parent to "active" too?

thank you

Link to comment
Share on other sites

Nobody? :D

I don't have a testcase setup handy but I think you just need to stop home (id:1) from the entering the dropdown-toggle code, maybe:

// first level items need additional attr
if($item->numChildren(true) && count($item->parents) < 2 && !$item->id=1){
    $title = $item->get("title|name");
    $event->return = '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $title . ' <b class="caret"></b></a>';
}
...

I'm not sure I understand what you mean by the "and make it href link work just for that parent?"

If I select the service one or two links in the services parent page, the children's class is "active" can I set the parent to "active" too?

Yes you can.

'parent_class' => 'active', // string (default 'parent') overwrite class name for current parent levels
  • Like 1
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...