[SOLVED] How to show autonav block if in a section?
Permalink 2 users found helpfulTrying to cut down on the number of page templates I'm creating for my clients, so was thinking I could hardcode an autonav depending on the section Im in.
For example, with the following sitemap, I need Section 1 and *all* it's subpages (including S1 2a and S1 2b) to show Autonav A, Section 2 and all its subpages to show Autonav B etc.:
Section 1
-S1 p1
-S1 p2
--S1 p2a
--S1 p2b
-S1 p3
Section 2
-S2 p1
-S2 p2
-S2 p3
Section 3
-S3 p1
-S3 p2
-S3 p3
--S3 p3a
--S3 p3b
Does anyone know how to do that please?
Thanks
osu
osu
So what you could also do is do something like $childrenOfHome = Page::getByID(HOME_CID)->getCollectionChildrenArray(true);
Load up the path back to home, which is under NvagiationHelper::getTrailToCollection(HOME_CID);
SO then you could do if each isn't empty then wherever they intersect(http://php.net/manual/en/function.array-intersect.php) in your nav template off that children array of 1(if you only want the first nav elements to be highlighted as active, or if you did getCollectionChildrenArray(false) then you have all of them, so then you could output an "active" li class or something like that.
G'Luck! :)
I don't really understand how your code works. How does it know it's in "Section1"? Because that's the name of the page?
I want to do the same thing as OP for a parent page named "The Way It Works" to display children subpages ONLY when on this page.
The Way It Works
> Child 1
> Child 2
What code do I need to add to my template?
Then depending on how you want to do it from there, be it via CollectionChildrenArray or a hardcoded autonav block, i'll leave that up to you :)