alan Posted May 23, 2012 Posted May 23, 2012 I have these pages: /fruit/ <- 'fruit' is not hidden /fruit/apples/ <- 'apples' is hidden /fruit/apples/green-apple/ <- 'green-apple' is not hidden I want 'fruit' to appear in the nav, it does, it's not hidden, all good. I want 'green-apple' to not appear in the nav, it doesn't, it's parent is hidden, all good. I want the contents of 'green-apple' to be findable by search, they are, it's not hidden, all good. When I click a search result link to 'green-apple' I see the page and no nav is 'lit-up' as this page's path into the nav is interrupted by the hidden page, no problem, I use this code to detect if the page displayed is under a hidden parent and if it is, display a breadcrumb: if($page->parent->isHidden()) { foreach($page->parents as $parent) if($parent->viewable()) echo "<li><a href='{$parent->url}'>{$parent->title}</a></li>"; } The problem I am seeing is that although the 'apples' page is set to Hidden, it is shown in the list of $parents, so it looks like I am misusing 'viewable()' in some way. Any pointers as to why this is happening and/or what I might do to fix? As ever, any comments most appreciated!
Soma Posted May 23, 2012 Posted May 23, 2012 You're missunderstanding viewable(). It's only for checking if a user has view permission. I think what you're trying to archive would be: if( !$parent->isHidden() ) ... Do a "page->is" search on the cheatsheet to see further methods. Edit: ...oh and I drink coffee not beer. Edit2: Damn you already got that in your code... (not enough coffee I guess) need to read again. lol Edit3: Ok I added a !, so this looks ok. Reading again you already got the answer there in the code. Anyway, as an alternative, you could also leave the apple page visible and create a special template ie. "redirect_xy", and use that to do redirects to the first child or anything you could specify. You then would also have to deal with the searchresult additionally, or maybe not. For example the: $session->redirect($page->children()->first()->url); Or maybe even add a page field (single) to the template to select the page to redirect to. $session->redirect($page->redirect_page->url); But your solution seems ok to me. Just wanted to give alternatives (for others and the record). 1
alan Posted May 23, 2012 Author Posted May 23, 2012 Soma I owe you a lake full of coffee. Thank you very much indeed. That solved it and this is the full working code: if($page->parent->isHidden()) { foreach($page->parents as $parent) if(!$parent->isHidden()) echo "<li><a href='{$parent->url}'>{$parent->title}</a></li>"; } Brilliantly easy (with PW and friends like Soma )
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now