Add a "content" Block with default content into all new Pages of my PageType

Permalink
Hi,

I am very new to C5 and using 5.7.5.9.

I have created a theme with a new template (Page Type) called "FaceSlap". when the user creates a new page with Page Type "FaceSlap" I want to include a "Content" block with my default content in an Area Named "XYZ"

I have Google searched and read 100 different things, none of which have helped me.
I think I need a PageTypeController with an add() function? If so direct me to something that tells me how to create one and where it goes in the file system.
Then I still need to know how to add a block to the page.

Currently, I only have the FaceSlap.php, description.txt and thumbnail.png files in the theme/<themename> folder.

Thanks in advance,
Sean

 
SeanDevoy replied on at Permalink Best Answer Reply
Solved it myself

Using the information here:https://www.concrete5.org/community/forums/customizing_c5/programmat... I was able to add the block in the <page style>.php. The trick was not to add a new block everytime the page was viewed.

In my case, I know I always want at least one content block in this area or the page is useless!

$a = new Area('MainUserContent');
$a->display($c);
if ($a->getTotalBlocksInArea() < 1) {
          $page = \Page::getCurrentPage();
          $content_block_type = BlockType::getByHandle('content');
          $def_content = array('content' => '<h1>Add your content here.</h1>',);
          $page->addBlock($content_block_type,'MainUserContent', $def_content );
}


Hope that helps someone else later.