Display Parent Page in Autonav

Permalink 1 user found helpful
Hi Everyone,

I'm a little bit stuck. I want to add the parent page too my customized Autonav block seen here:http://logisticadev.net/resources/...

On the left it displays the subpages for Resources but I'd like it to display the link for the resources page link too.

I used the following code found in another post:
$page = Page::getByID($c->getCollectionParentID());
print $page->getCollectionName();


But it just displays HOME

I've got as far as putting the custom template code in the /blocks/autonav/templates/ and applied my own styles. 95% done. It would be nice to show the parent page too.

Thanks

brandonx49
 
cherrycake replied on at Permalink Reply
cherrycake
The reason you see HOME displayed is because $c references the current page instance you're viewing. With other words it's relative to where you are. So if you use $c->getCollectionParentID() you will always get the parent from where you are.

If you see HOME, it means you're currently viewing /resources/. If you click on a subpage, you should see Resources instead of home since you're currently viewing /resources/subpage.

Instead i would try and look for whatever object is used in your template to retrieve it's child pages, cause that object would obviously be the Resources collection. Then just before the iteration starts, use that object to call getCollectionName();

Hope that helps.
rlekhanya replied on at Permalink Reply
rlekhanya
Try this:
$parentPage = Page::getByID($c->getCollectionParentID());
echo '<a href="../">' . $parentPage->getCollectionName() . '</a>';
jordanlev replied on at Permalink Reply
jordanlev
Cherrycake is correct. You can use $_c in stead of $c (so an underscore between the dollar sign and the letter c) to get what you want. For example:
$_c->getCollectionParentID();