Best way to get root+1 page for subnav in all descendant pages

29 views
Skip to first unread message

Brian Ross

unread,
May 18, 2013, 5:39:16 PM5/18/13
to apostr...@googlegroups.com
I am looking for the best way to interrogate the `aNavigationTabs` Tree to get root + 1 level, with the associated page name and information associated with it. Is there a tools->getPageInfo("/contact") type thing I can use?

For example, if my menu is

Home
    About
    Contact  <-- root + 1 for Chicago page
        Jobs
        Locations
            Helsinki
            Chicago  <-- Current page
            San Francisco

and I'm on the Chicago page, I need to get the page info for Contact; I also need to render a subnav that starts from that level as well. 

While on the Chicago page, the subnav would display root+1 and all descendants:

Contact  <-- root + 1 for Chicago page
    Jobs
    Locations
        Helsinki
        Chicago  <-- Current page
        San Francisco

I am currently using $this->uri = $request->getPathInfo() in the component actions to pass to the subnav, but that seems hacky...

So I get the path, and then split on / to get the top level page slug to feed a subnav's `$root` option, but that doesn't get me all the info associated with a page and the name. I need to display the 'nice' page name for root+1 when I'm on any descendant page.

Is there a built-in/recommended way to get 
  1. Page path for root+1 on any descendant page?
  2. Page info for root+1 path? (Mostly need 'nice' name for a particular slug.)
  3. Both at the same time without $request->getPathInfo() hack?
I'm still studying the code that drives the `aNavigation...` classes to find this stuff and have gotten stuck with too much recursion and memory being used up, just hoping someone could point me in the direction of some magic.

Right now one approach I'm favoring is to get the entire navigation structure to hide/show with css+javascript based on the URI and adding some extra attributes to the nav structure for nice names. I'm still grokking the classes for "ancestor-peer" and the like.

Another approach would be to create separate templates for each top level that I need the nav to start from and simply hard code in $root for each aNavigation component (only 3 of these; not as future proof but in this project apostrophe is acting more as a development speed-up rather than allowing the client to add new pages on their own ad infinitum). 

Thanks!

also on SO since I've had trouble posting to this group the past few days: 

Tom Boutell

unread,
May 18, 2013, 5:49:38 PM5/18/13
to apostr...@googlegroups.com
You could write:

$root = aPageTable::retrieveBySlug('/');
$info = $root->getChildrenInfo();

This will give you an array of associative arrays each of which has title, slug, id, etc. attributes, everything you need for navigation but not the memory and CPU demands of hydrating full Doctrine objects. (You will get a full object for the root page.)




--
You received this message because you are subscribed to the Google Groups "apostrophenow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apostropheno...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Tom Boutell

unread,
May 18, 2013, 5:51:18 PM5/18/13
to apostr...@googlegroups.com
Actually, you can also write:

$page->getAncestorsInfo()

Which gives you info arrays for all the ancestors of the current page ($page is already set in your page template), and this allows you to write:

$ancestors = $page->getAncestorsInfo();
$root = $ancestors[0];
$tabs = aPageTable::getChildrenInfo($root);

(Note that the table class version of getChildrenInfo will accept an associative array.)

Hope this gets you there!

Brian Ross

unread,
May 18, 2013, 9:05:25 PM5/18/13
to apostr...@googlegroups.com
Thanks! Exactly the hints I was looking for.
Reply all
Reply to author
Forward
0 new messages