Adding Custom Template to a Block programmatically
Permalink
So here's what I'm doing:
The formatting is working, bName too, bIsActive also, but bFilename is not rendered on the page. So how to set a custom template on that newly created block?
$data = array( 'formatting' => 'h1', 'bFilename' => 'byline.php', 'bIsActive' => '1', 'bName' => 'block_name'); $bt_title = BlockType::getByHandle('page_title'); $ax = Area\Area::getOrCreate($page, 'Main'); //$page is the page object $page->addBlock($bt_title, $ax, $data); // Or like that $bt_title->add($data); $page->addBlock($bt_title, $ax, array());
The formatting is working, bName too, bIsActive also, but bFilename is not rendered on the page. So how to set a custom template on that newly created block?
Actually
Will return the block object so you can just do
$page->addBlock($bt_title, $ax, $data);
Will return the block object so you can just do
$b = $page->addBlock($bt_title, $ax, $data); $b->setCustomTemplate('byline.php');
Oh Man I was making it real complicated... Thank you!
The thing is that the block needs to be saved before adding a template:
That's it