Quantcast
Channel: Planet Apache
Viewing all articles
Browse latest Browse all 9364

David Reid: Concrete 5 – Add Block to page_type

$
0
0

When writing the page_type template it’s possible to embed to areas using the standard area code,

$a = new Area('area_name'); $a->display($c);

Using the Defaults option on the Dashboard / Page Types screen it’s then possible to add blocks to the area you created. In my case I was installing the page_type as part of a package so I didn’t want to have to ask people using it to add in blocks themselves. After some help from someone on IRC I added the following code which allows me to add a content block to the area with some default content.


$pagetype = CollectionType::getByHandle('page_type');
$mt = $pagetype->getMasterTemplate();
$bt = BlockType::getByHandle('content');
$mt->addBlock($bt, 'area_name',
array('btConfig' => '1',
'content' => 'Default content'));

The trick turned out to be getting the master template for the page_type you have just installed and then adding the block to that using the standard addBlock() call.

As I’ve just wasted a fair bit of time searching for a bug in my code that turned out to be a simple spelling mistake, make sure you have the same name for the area in the page_type template and in the above code :-)


Viewing all articles
Browse latest Browse all 9364

Trending Articles