inserting autonav, automatically?

Permalink
Hi - I've got a package here where I've figured out how to add a single page during the installation and add the single page the sitemap. However, when you navigate to that new page after install, the autonav element is gone.

Can anyone provide me with the code I need in order to add the autonav block onto this new single page during the package install?

Many thanks!!

torchmedia
 
Mnkras replied on at Permalink Reply
Mnkras
you could look in almost any theme package and find this:

Add a block to a page's "Main" area
Let's say your block has a handle of "t_shirt" and has four parameters, named "name," "color," "size," and "type". Here's how you'd add that block to the "Main" area on a page, programmatically:
$bt = BlockType::getByHandle('t_shirt');
$data = array(); 
$data['name'] = 'Test Shirt';
$data['color'] = 'black';
$data['size'] = 'M';
$data['type'] = 'athletic';
$c = Page::getByID('/my/shirts/page');
$c->addBlock($bt, 'Main', $data);


i took that out of the dev docs

im not sure what the auto nav handle is or the option variables in it but it would be something like this i think:

$bt = BlockType::getByHandle('auto_nav');
$c->addBlock($bt, 'Main');


this adds the autonav block to an area called Main.

Hope this helps

Mike
torchmedia replied on at Permalink Reply
torchmedia
The code below works upon initial install but there are a couple of issues that crop up:
$bt = BlockType::getByHandle('autonav');
$data = array();
$data['orderBy'] = 'display_asc';
$data['displayPages'] = 'top';
$data['displaySubPages'] = 'none';      
$c = Page::getByPath('/sermons');
$c->addBlock($bt, 'Header Nav', $data);

It inserts the autonav block into the page, but for some reason it uses a different css class. The original pages all use class="nav-header", but this new block uses class="nav". Weird??

Secondly, I tried changing the theme to see what would happen. The autonav block disappeared from the page after the theme change. Is this a bug?