Hard code a block into a theme, allow end-user to edit block

Permalink
Does anyone know how to allow a block to be edited once it has been hard coded into a theme?

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...

<?php
$mainnav = BlockType::getByHandle('autonav');
$mainnav->controller->displayPages = 'top';
$mainnav->controller->orderBy = 'display_asc';
$mainnav->controller->displaySubPages = 'none';
$mainnav->render('view');
?>

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.

 
Mainio replied on at Permalink Reply
Mainio
This could probably be done using stacks. Take a look at this one (also the video):
http://www.concrete5.org/documentation/how-tos/developers/concrete5...

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).
rrcustom replied on at Permalink Reply
I thank you for your reply. It is greatly appreciated.

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?
glockops replied on at Permalink Reply
glockops
<?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.
rrcustom replied on at Permalink Reply
I am going to spend some more time looking into page defaults but I still want to know if I can hard code a block and still allow that hard coded block to be editable?
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
You wont be able to hard code a block and it be editable. What you may be able to do is to hard code the creation of a block, which would then be editable by the usual means.

C5 already has mechanisms for creating default content when a package is installed. Perhaps you can use or adapt that.
rrcustom replied on at Permalink Reply
Thank you for answering my question. Sounds like my only ideal option without custom coding is to utilize page defaults.
nomaknz replied on at Permalink Reply
Hi,

I also needed to be able to hard code an editable block, did you manage to find a solution? Any help appreciated. Thanks!
rrcustom replied on at Permalink Reply
No. You have to utilize page defaults to do this.