Hard coding Autonav

Permalink
Hi Guys

I want to hard code an autonav setup into a block so the client doesn't have to keep using it over and over again.

The setup i want to achieve is:

Pages should appear - in their sitemap order
Display pages - at the top level
Subpages to display - Relevant sub pages
Sub page levels - display sub pages to current +1

The code i've got is:

<?php
    $bt_main = BlockType::getByHandle('autonav');
    $bt_main->controller->displayPages = 'top';
    $bt_main->controller->orderBy = 'display_asc';
    $bt_main->controller->displaySubPagesLevels = 'enough_plus1';
    $bt_main->controller->displaySubPageLevelsNum = 'relevant';
    $bt_main->render('view');
?>


It displays the top level fine but won't display the subpages when on the current page (as it does if i use the autonav block within the cms).

So can anyone tell me where i am going wrong?

Thanks,

Jeb

 
TooqInc replied on at Permalink Reply
TooqInc
I'm not sure you need to hard code this, but rather set up the page defaults to include the auto-nav automatically (Dashboard >Pages & Themes >Page Types >Defaults).

The nav order is based on the sitemap order and you can usually have this line up correctly using a little client training and permissions management.

Sub-pages will show based on the "Exclude from nav" attribute. This can also be set in the page defaults, though I usually show clients doing their own edits this too so they can self manage.

I know there are a few custom menus in the marketplace that might have deeper functionality than the rest, but I've managed to get by as noted above.
Jebediah replied on at Permalink Best Answer Reply
Thanks tooq for such a quick reply!

I think i've cracked it. I couldn't work out where the attributes were and i had my code wrong too.

Oh and if anyone else is confused as to where the attributes are look in: autonav > form_setup_html.php . That file has all the attributes for the autonav that u can use in hardcode. Just incase anyone else has the same confusion.

<?php   
 $navBT = BlockType::getByHandle('autonav');
     $navBT->controller->displayPages = 'top';
     $navBT->controller->orderBy = 'display_asc';
     $navBT->controller->displaySubPages = 'relevant';
     $navBT->controller->displaySubPageLevels = 'enough_plus1';
     $navBT->render('view');
?>
TooqInc replied on at Permalink Reply
TooqInc
Hmm. Might just have to play around with that code snippet...
Jebediah replied on at Permalink Reply
yeah works a treat. Essentially it just replicates what the cms does but its hard coded.

Another useful snippet

<?php
      $bt = BlockType::getByHandle('autonav');
      $bt->controller->cParentID = '80';
      $bt->controller->displayPages = 'current';
      $bt->controller->orderBy = 'display_asc';
      $bt->render('view');
      ?>


Which is awsome for using in sites where u have a fixed nav with a dropdown. Just whack the above code in the dropdown div and change the ID to the ID of the current page and it'll show all subpages below that page. Works well (found it on the forum). Very handy :)