Hard-coding dynamic blocks

Permalink 1 user found helpful
Hi,

Is there a way to hard-code blocks into a template so that a client can't change them? For example, I want to hard-code an auto-nav into my template so my client client can't add another block to the same area and destroy the layout?

Thanks,

osu

osu
 
katz515 replied on at Permalink Reply
katz515
You can already do that by using Advanced Permission

http://www.concrete5.org/help/building_with_concrete5/installation/...
osu replied on at Permalink Reply
osu
I'll look into advanced permissions now then. Thanks katz515
matogertel replied on at Permalink Reply
matogertel
Hi, I use this code in most of my themes. It's much easier to maintain than advanced permissions and default blocks.
It's a bit tricky to get the correct variables and values without the gui, but that doesn't mean you can't do it.
$bt = BlockType::getByHandle('autonav');
                  $bt->controller->displayPages = 'top';
                        $bt->controller->orderBy = 'display_asc';
                        $bt->controller->displaySubPages = 'none';
                        $bt->controller->displaySubPageLevels = 'all';
                        echo $bt->render('view');

Btw, you can use a similar code for any block, but most blocks need a proper entry in the database in order to work correctly so the results are not always as expected.
Another way to hard code blocks into the template is add them to the scrapbook and then call them from there. There's a post somewhere explaining how to do it. I'll see if I find it and will post a link.
matogertel replied on at Permalink Reply
matogertel
Here's another thread describing other ways of doing it.
Look for Tony's suggestion towards the middle, although the other suggestions are good aswell.
http://www.concrete5.org/index.php?cID=13668...
osu replied on at Permalink Reply
osu
Thanks martogertel, the scrapbook option works great for me - still going to look into Advanced Permissions as they look like they could be useful for other areas of this site I'm working on.

Thanks to both of you for the help
eOne replied on at Permalink Reply
I have problem getting this based on your example.

How would you add image block from image/file attribute?