Adding Blocks to Scrapbook in a Package

Permalink 9 users found helpful
Hello, I am setting up a package so that I can install a default site easily. I was wondering if there is a way to add a Block to the scrapbook using code.

So for example If I wanted to add a text block to the scrapbook from the package controller. Rather than the interface.

Or do I just add the block straight into the database using a MYSQL statement?
Thank you for any help

View Replies:
jero replied on at Permalink Reply
I just tried to do exactly that. After a bit of thought, I came up with this:

$helper = Loader::helper('concrete/scrapbook');
$cb = BlockType::getByHandle('content');
$data['content']='<p>Some Content</p>';
$block=$sb->addBlock($cb, "Global", $data);
// optionally change the name of the block in the scrapbook
$block->updateBlockName('MyBlockName', $force=1);

This of course assumes you're using a content block. Other block types will have different values for the data array. The best source of documentation would be in the controller for each block type.