Programatically Adding Content Blocks
Permalink 2 users found helpful
Hi, I have a package controller that is adding a page to the website then adding a content block to the page with some sample content:
That will add a Content block to the main area, but what I really want to do is add the sample data to a Composer Content Block on the page type used.
Right now I get the new Content Block below the Composer Control Block. Can anyone point on how to replace that control block with the content block?
thanks
$block = BlockType::getByHandle('content'); $data = array( 'content' => '<p>'Sample Content '</p>', ); $newPage->addBlock($block, 'Main', $data);
That will add a Content block to the main area, but what I really want to do is add the sample data to a Composer Content Block on the page type used.
Right now I get the new Content Block below the Composer Control Block. Can anyone point on how to replace that control block with the content block?
thanks
Thanks for posting your code, it helped me solving my own problem (I was trying to pass to addBlock either 2 objects or 2 strings in $bt and $a; how could I have guessed $bt is an object and $a is a string??? maybe the API documentation should be improved a bit...)
As for your issue, I don't get what you're trying to accomplish: are you trying to publish your content in a global area of a page type, as to have it pre-written there when a user makes a new page from it?
I am not sure what you mean by composer's "control block". Can you provide a screenshot to see them both: where it appears now vs. where you want it ?
Cheers,
Lian