Jump to content

Recommended Posts

Posted

Hello,

what I want to do is something like this: (for my navigation)

list:
----------
home
    page-1
    page-2 class='current'
        page-2-1
        page-2-2 class='current'
        page-2-3
    page-3
        page-3-1
        page-3-2
    page-4
    ...
----------

I have tried some but did'nt find a way for the parents.

I'm sure, the solution is as simple as columbus egg...

Any help for me?

Thank you.

Posted

Use something like this:

foreach(… as $item){
  …
  if($page->parents->has($item)) $class .= " current";
  …
}

You just need to adapt it to your way of building the nav structure.

  • Like 1
Posted

TL;DR:

$node->children->has($page) 

Guessing that you iterate over your pages. Let's say your page-2 is currently held in $node, you could do something like:

$class = '';
if($node->children->has($page)) {
    $class = 'current';
}

echo '<li><a .... class="' . $class . '">...';
Posted

Thank you. 

I've tried it with

$node->children->has($page)

looks very good but it dit not work. (in the _main.php template) Don't know why.

So I build it my own way.

May be not elegant, but it works.

<nav class="PV" id="navigation"><ul>
		<!-- top navigation -->
		<?php
		foreach($homepage->and($homepage->children) as $item){
			if($item->name=='site-map') continue; // hide site-map

			if($item->id==$page->rootParent->id){
				echo $page->id==$item->id ? "<li class='active'>" : "<li>";
				} else { 
				echo "<li>"; 
				}
			
			echo "<a href='$item->url'>$item->title</a>";
			
			if($item->name == 'home'){
				echo "</li>";
				continue; // don't open the children if homepage
				}
				
			if($item->numChildren(true) && $item->id == $page->rootParent->id) {
            	echo "<ul>";
                foreach($item->children as $sub_item) {
                	echo $page->id==$sub_item->id ? "<li class='active'>" : "<li>";
                        echo "<a href='$sub_item->url'>$sub_item->title</a></li>";
                	}
            	   echo "</ul>";
				}
		echo "</li>";
		}
		
		// output an "Edit" link if this page happens to be editable by the current user
		if($page->editable()) echo "<li class='edit'><a href='$page->editUrl'>Edit</a></li>";
		
		?>
		</ul></nav>

Thank you again. Whether I use you suggestions or not - your feedback is allways important for me to find the point.

Matthias

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.
×
×
  • Create New...