Dynamic Subpage Menu Problem

Permalink
My site has menus that are three levels deep. Somthing like this:

Home
Item 1
---Sub 1
------Sub 1.1
------Sub 1.2
------Sub 1.3
---Sub 2
------Sub 2.1
------Sub 2.2
------Sub 2.3
---Sub 3
------Sub 3.1
------Sub 3.2
------Sub 3.3
Item 2
Item 3
Item 4

I want my sidebar menu to display the 3rd level pages (which I can do just fine with an AutoNav). However, I ALSO want the PARENT item to those subpages without displaying all of them. So if I'm on page Sub 3.3, then I want my menu to look like this:

Sub 3
---Sub 3.1
---Sub 3.2
---Sub 3.3

Is there a way to do this? I can't seem to get just the parent item of the current page to display.

leinteractive
 
jordanlev replied on at Permalink Reply
jordanlev
Hey Travis.
I would make a custom autonav template for use with these menus and add in a link to the parent page before it starts outputting the sub-pages. Assuming the menu is displayed on sub-pages only, you can just get the parent page via Page::getByID($c->getCollectionParentID())
leinteractive replied on at Permalink Reply
leinteractive
I thought it would be some sort of custom template thing.

I don't need a link to the parent page...just the name of the parent page. Is the ID the same thing as that?
leinteractive replied on at Permalink Reply
leinteractive
Apparently I'm not doing something right.

I added this to the top of my auto nav to get the Parent Page:

$parentName = Page::getByID($c->getCollectionParentID());


And then I added this right before the menu itself starts printing out:

echo("<h2>" . $parentName . "</h2>");


But I get this error when I test it on the site:

Catchable fatal error: Object of class Page could not be converted to string in /blocks/autonav/templates/display_parent_page.php on line 36
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Ahh, sorry I wasn't too clear in my initial response.
That function returns the page object, which is like a happy meal bag full of various info about the page -- you generally can't just output objects because they are like structures of data in memory and not necessarily translatable to text. What you need to do is pull out the specific info you need from the object. So if you want the page name, do this:
$parentPage = Page::getByID($c->getCollectionParentID());
//...later on...
echo "<h2>" . $parentPage->getCollectionName() . "</h2>";
leinteractive replied on at Permalink Reply
leinteractive
Aha! That did it! Great, thanks.

A happy meal full of goodies. I like that analogy. ;-)