Programmatically adding auto-nav

Permalink
I've inherited a site that has the global header nav set up as a GlobalArea in the theme's header.php file, like so:

$a = new GlobalArea('Header Nav');
$a->display();


We are now internationalizing the site so I was thinking I would convert this to a fully programmatically generated autonav BlockType but I don't know how to get it to actually display. Here's where I'm at:

$autonavBT = BlockType::getByHandle('autonav');
$autonavBT->controller->displayPages = 'custom';
$language = Loader::helper('section', 'multilingual')->getLanguage();
$navRootPage = Page::getByPath('/'.substr($language, 0, 2)); // es, en, etc.
$autonavBT->controller->displayPagesCID = $navRootPage->getCollectionID();
<other $autonavBT options here>


But how do I get the $autonavBT to display on the page? All of the examples want me to render it into a template view using something like:

$autonavBT->render('view');


But that will require more in-depth refactoring so I'm hoping to just display it in-line. Is it possible?

 
nklatt replied on at Permalink Reply
Le sigh. I had my other options wrong on $autonavBT. Got those sorted and the $autonavBT->render('view'); call displays it beautifully. Wish I could just delete the op! Then again, it is a kinda slick way to embed the autonav in an i18n site, I think. Full code is as follows:

$autonavBT = BlockType::getByHandle('autonav');
$autonavBT->controller->displayPages = 'custom';
$language = Loader::helper('section', 'multilingual')->getLanguage();
$navRootPage = Page::getByPath('/'.substr($language, 0, 2)); // es, en, etc.
$autonavBT->controller->displayPagesCID = $navRootPage->getCollectionID();
$autonavBT->controller->orderBy = 'display_asc';
$autonavBT->controller->displaySubPages = 'all';
$autonavBT->controller->displaySubPageLevels = 'custom';
$autonavBT->controller->displaySubPageLevelsNum = '1';
$autonavBT->render('view');