Can you add conditionals to the autonav block when embedding in a template?
Permalink
Hi There,
I'd like to use the same right_sidebar.php template for when the template is at different levels.
e.g When the template is at the top level, display this, when the template is at level 1, display this etc.
Are there conditionals that could be used to achieve this?
Any help would be appreciated.
Cheers
Ben
I'd like to use the same right_sidebar.php template for when the template is at different levels.
e.g When the template is at the top level, display this, when the template is at level 1, display this etc.
Are there conditionals that could be used to achieve this?
Any help would be appreciated.
Cheers
Ben

Just choose "at the current level" for the "display pages" dropdown when adding/editing the autonav block.
Thanks for that,
I'm having a bit of trouble working out the parameters when embedding the block in a template - I tried this:
But it displays "Home" when the template is on a top level page - that's why I was wondering about conditionals?
When the template is at the top level I'd like it to display the name of the current page. When it's a level down, I'd like it to display it's parent first, then the children at the same level.
Not sure if this is possible based on what I've read though.
I'm having a bit of trouble working out the parameters when embedding the block in a template - I tried this:
$bt_main->controller->displayPages = 'current_level';
But it displays "Home" when the template is on a top level page - that's why I was wondering about conditionals?
When the template is at the top level I'd like it to display the name of the current page. When it's a level down, I'd like it to display it's parent first, then the children at the same level.
Not sure if this is possible based on what I've read though.
Just check if its the Home Page,
if($c->getCollectionID == HOME_CID) { //its the homepage }
Thanks for that, but I'm not having this issue on the home page - pages one level down are displaying "Home" in their sidebar menu.
Is there a way to check to see if a page is at a certain level?
Is there a way to check to see if a page is at a certain level?
I think it's just:
$bt_main->controller->displayPages = 'current';
Thanks Jordan,
Not sure if I've done this correctly but it works so am posting these for my reference incase I forget.
I wouldn't mind your opinion as I don't know any PHP so just guessed.
Firstly, the structure:
Home
__|Recipes
____|_Recipe one
____|_Recipe two
CODE SNIPPET ONE - don't display children when on parent:
- Displays Recipes only when on the Recipes page
- Displays Recipes, Recipe One, Recipe Two when on children
CODE SNIPPET TWO - display children when on parent:
- Displays Recipes, Recipe One, Recipe Two when on the Recipes page
- Displays Recipes, Recipe One, Recipe Two when on children
Cheers
Ben
Not sure if I've done this correctly but it works so am posting these for my reference incase I forget.
I wouldn't mind your opinion as I don't know any PHP so just guessed.
Firstly, the structure:
Home
__|Recipes
____|_Recipe one
____|_Recipe two
CODE SNIPPET ONE - don't display children when on parent:
- Displays Recipes only when on the Recipes page
- Displays Recipes, Recipe One, Recipe Two when on children
<!-- sub navigation --> <ul class="s-nav"> <!-- Always display parent unless on level 1 --> <?php $title = $c->getCollectionName(); $parentPageId = $c->getCollectionParentID(); if ($parentPageId > 1) { $parentPage = Page::getById($parentPageId); $title = $parentPage->getCollectionName(); $url = View::URL($parentPage->getCollectionPath()); } else { $url = DIR_REL; } ?> <!-- render parent in li -->
Viewing 15 lines of 29 lines. View entire code block.
CODE SNIPPET TWO - display children when on parent:
- Displays Recipes, Recipe One, Recipe Two when on the Recipes page
- Displays Recipes, Recipe One, Recipe Two when on children
<!-- sub navigation --> <ul class="s-nav"> <!-- Always display parent unless on level 1 --> <?php $title = $c->getCollectionName(); $parentPageId = $c->getCollectionParentID(); if ($parentPageId > 1) { $parentPage = Page::getById($parentPageId); $title = $parentPage->getCollectionName(); $url = View::URL($parentPage->getCollectionPath()); } else { $url = DIR_REL; } ?> <!-- render parent in li -->
Viewing 15 lines of 29 lines. View entire code block.
Cheers
Ben
Actually - it doesn't work!
The link to Recipes on the Recipes home page actually links back to the Home page and the second option doesn't display the children on the recipes home page - bummer!
Do you have to clear the cache when making changes like this - I could've sworn that it all worked
The link to Recipes on the Recipes home page actually links back to the Home page and the second option doesn't display the children on the recipes home page - bummer!
Do you have to clear the cache when making changes like this - I could've sworn that it all worked
Hmm... I'm a little confused about what exactly you're trying to achieve. But in general, when I have different autonav needs on different levels of the site, instead of trying to make one autonav template that satisifies everything, I instead make different custom templates, each of which does what I want (and you could even hard-code in the link to the "parent page" at the top of one of them if that's something you want in there).
In order for this technique to be sane, it requires that you have different page types set up for the different levels of the site (because you want to be able to either hard-code these autonav blocks into the page type templates or you want to be able to put them into the Page Defaults, each of which is on a per-page-type basis). So in your example you'd have "Recipe Listing" and "Recipe Detail" as two different page types (for example). So depending on what the rest of your site structure is like, this may or may not be feasible -- but this is the approach I'd try first before getting crazy with autonav logic.
-Jordan
In order for this technique to be sane, it requires that you have different page types set up for the different levels of the site (because you want to be able to either hard-code these autonav blocks into the page type templates or you want to be able to put them into the Page Defaults, each of which is on a per-page-type basis). So in your example you'd have "Recipe Listing" and "Recipe Detail" as two different page types (for example). So depending on what the rest of your site structure is like, this may or may not be feasible -- but this is the approach I'd try first before getting crazy with autonav logic.
-Jordan
When the template is at the top level I'd like it to display the name of the current page. When it's a level down, I'd like it to display it's parent first, then the children at the same level.[URL=http://www.replicabagshotsell.com]replica designer handbags[/URL]