Can you add add-ons to a template?

Permalink
Hi,

I am designing a template and i want to add the superfish add-on to the template so i don't have to stick the add-on in every page seperatly.

Is this possible to do?

 
ScottC replied on at Permalink Reply
ScottC
yeah no problem, replicate the file structure in your package and it is picked up, just like you would do if you were modifying a file outside of core.

The package i believe needs to be installed, but it does in fact work.

-Scott
aberbenni replied on at Permalink Reply
aberbenni
Very bad way, is there a more "object oriented" way of doing it?
glockops replied on at Permalink Reply
glockops
This have changed a lot since the original question.
And the question could refer to quite a few things.

Here's some help.

If you want to include an add-on in a theme package, then you can use the package's controller to install the add-on. You'll need to reference the developer docs for assistance.

If you want to include a custom template for an add-on in a theme, then just include a "blocks/{blockname}/templates/mytemplate folder that overrides the view.php (and other needed files). This behaves just like a custom template typically does.

If you want to include a block in a page type (which sounds like what this original question was) there are two methods of doing it.
The first is to insert code like the following:
<?php
// Automatic Sidebar Navigation
$nav_side = BlockType::getByHandle('autonav'); 
$nav_side->controller->displayPages = 'custom'; 
$nav_side->controller->displayPagesCID = $si->getCollectionID();
$nav_side->controller->orderBy = 'display_asc'; 
$nav_side->controller->displaySubPages = 'all';
$nav_side->controller->displaySubPageLevels = 'custom';  
$nav_side->controller->displaySubPageLevelsNum = 2;
$nav_side->controller->displayPagesIncludeSelf = 1; 
$nav_side->render('templates/sidenav');
?>

The benefits of this method include the ability to make programmatic changes to the block for a specific page. Here $si is an "index" that is determine with a custom attribute. The cons are that this method is not efficient and can interfere with the cache (ie slower site)

The second method is to insert a "Global Area" into your page type:
<?php
$sbn = new GlobalArea('Sidebar Nav');
$sbn->display($c);
?>

This allows you to insert a block (or blocks) into this area and it/they will appear on all page types that have this global area present.

Hope that clears up some confusion.