Hard code a block into a theme, allow end-user to edit block
For example, using the code below. This will embed the navigation block where ever it is placed. When the a new page is added and the theme is selected, the navigation shows up as it should but when you go into edit mode, you cannot edit the "block". It is literally hard coded in. From what I can gather, that is how it is suppose to function...
$mainnav = BlockType::getByHandle('autonav');
$mainnav->controller->displayPages = 'top';
$mainnav->controller->orderBy = 'display_asc';
$mainnav->controller->displaySubPages = 'none';
My question, is there a way to allow the hard coded block to be edited when the page is put into edit mode?
Any help is greatly appreciated. I've searched all over google/the forums and I can't find an answer.
Just add a stack or global area to that place in your theme and add this block to that stack (global areas are also special kind of stacks) during your theme's installation process.
EDIT: And by the way, if that's a global area you can also limit the number of blocks in that area so that users cannot add any additional blocks there with function $ga->setBlockLimit(1).
I am very aware of stacks and global areas. I use them elsewhere in my C5 instance. For logistical reasons, I need to hard code the blocks into place so my users don't have to add them in.
Do you know of any way to hard code the block and enabled editing of that hard coded block when going into edit mode?
<?php $nav= new GlobalArea('Sidebar Navigation'); $nav->display($c); ?>
This will insert a new Area into your template which will display the same content everywhere the area is mentioned.
Remove your hard-coded navigation and replace with the above. Then insert an autonav block into the "Sidebar Navigation" area while in edit mode.
Keep in mind, editing it on one page will change it everywhere. If you're looking to insert an autonav block, but want to allow certain pages to have a slightly different autonav block, you'll need to set up "Page Defaults", inserting an autonav block into a sidebar area and then running "Setup on Child pages" to force it onto existing pages in your site.
C5 already has mechanisms for creating default content when a package is installed. Perhaps you can use or adapt that.
I also needed to be able to hard code an editable block, did you manage to find a solution? Any help appreciated. Thanks!