Subnavigation hardcoded

Permalink
I like to know what the best way is to display a submenu. I have the following hardcoded in my page template:
$nav = BlockType::getByHandle('autonav');
$nav->controller->orderBy = 'display_asc';
$nav->controller->displayPages = 'below';
$nav->controller->displaySubPages = 'all';
$nav->controller->displaySubPageLevels = 'enough';
$nav->render('templates/subnav');


It shows the pages under the current page (because of: $nav->controller->displayPages = 'below';). I would like it to show all the sublinks under the page at the second level. But only from 1 page not all pages of the links from second level. (see attachment). I tried
displayPages ='second_level'
but then it shows all links at the second level.

I don't get it to work like I would (see attachment). Any idea or other suggestions?

1 Attachment

 
ConcreteOwl replied on at Permalink Reply
ConcreteOwl
studio4graphics replied on at Permalink Reply
JohntheFish replied on at Permalink Reply
JohntheFish
Hard coded navigation is not a good solution. Whilst the (wrong) assumption is that a hard coded autonav is fast because it is hard coded, it is in fact always slow because the navigation is not cached. The database queries involved in resolving an autonav are often the biggest single issue in a slow TTFB.

On the other hand, if you actually add an Autonav block in a global area on the page, it will get executed once (slow) and then cached (very fast).

If Autonav in a global area has performance issues and your nav does not change often, use a Manual Nav or Nested Manual Nav block in a global area (both blocks in marketplace). Enable caching. Both are much more efficient than Autonav. Nested Manual Nav is a good block to use because it is 100% compatible with Autonav templates.

You can then assign your subnav template to the block through the design menu.
studio4graphics replied on at Permalink Reply
Thank you for explaining. I'm going to use autonav in a Global Area. Didn't know that it affects TTFB.

And going to create an extra page template to display a other autonav block with other options. That way I believe is the best way to make It as dynamic as possible.
mnakalay replied on at Permalink Reply
mnakalay
What might also help when there's no choice but to keep the hard-coded autonav is to use this package:https://www.concrete5.org/marketplace/addons/advanced-cache...

It will cache hard-coded blocks with a nice level of control.