Embed navigation into all pages

Permalink
Hi all,

Concrete n00b here. Getting my feet wet on what I thought was a "simple" project for a friend's consulting company... about 7 or 8 pages, simple content, nothing fancy. I want to turn it over her once I'm done populating it with the initial content so that she can manage it from there on out (preferably, with little input from me).

So... I'm trying to get used to the idea of having editable areas on the page, but want to ensure that there's not too much she can mess up when it comes to the layout and design.

So... there's going to be a left-hand navigation area on every page. I'd like to "hard-code" the C5 PHP in somewhere, but I don't know where (I thought I could do it in the default.php file of the theme I'm creating, but that didn't work). I want the navigation to be dynamic... so that she can add/delete pages and have the nav reflect that... but having an Auto-Nav block added to the page (even if done as a default on the page type) seems dangerous... she can edit it and/or delete it, even by mistake. So, can this be done?

Thanks!

bcbounders
 
thephilm replied on at Permalink Reply
thephilm
Couple ways to do it.
If you want the block to be completely non-editable by the end user then you can put code like this in the template:
<?php
    $bt_main = BlockType::getByHandle('autonav');
    $bt_main->controller->displayPages = 'top';
    $bt_main->controller->orderBy = 'display_asc';                    
    $bt_main->controller->displaySubPages = 'none';                    
?>

As you can see, it follows the form questions... you can look at the source code for the auto_nav block and see your options, but pretty self explanatory. so this code would go into your default.php file and it would render out an autonav block.

You could also setup the autonav block in a page default, which would allow some editing of the block in the backend. With a little bit of access control, you could limit who could edit the block...
Let me know if this works for you!
-Phil
beebs93 replied on at Permalink Best Answer Reply
beebs93
Phil's on the right track, but he accidentally omitted the last line which actually renders the block.

$bt_main = BlockType::getByHandle('autonav');
$bt_main->controller->mainCollection = $c;
$bt_main->controller->displayPages = 'top';
$bt_main->controller->orderBy = 'display_asc';
$bt_main->controller->displaySubPages = 'relevant';
$bt_main->controller->displaySubPageLevels = 'all';
$bt_main->render('templates/customnav');


This is a generic example I've used on other forum posts where I hardcoded an autonav block and rendered it with a custom template.

If you're using the normal template you could change that last line to:

$bt_main->render('view');


This will use the autonav block as usual, but it will remain unchangeable in terms of functionality (unless they can edit the template code itself).

Phil's last suggestion about using page defaults works as well, but as he hinted at it would limit access; not deny it across the board. A user with the right access could still technically remove it and break your design.

Typically, for navigation or something as equally as essential I hard-code it as shown since it's not something you want to accidentally be deleted.
bcbounders replied on at Permalink Reply
bcbounders
Thanks loads, Phil & Bradley! That did the trick! I had tried something similar before posting, but it didn't work... guess I botched the code somehow. But a copy-and-paste from your replies did it lickety-split.

Thanks! It's the helpful, FAST responses on this forum that really make Concrete5 wonderful (oh... that, AND the incredible code. Can't forget the code, LOL!)!

Really appreciate the help.

Cheers!

- John
thephilm replied on at Permalink Reply
thephilm
That's one of the reasons I love using Concrete5 myself.
Also - thanks Bradley - I realized the code snippet I've got saved locally, is the one you've posted through the forums! Saved me tons of time and headaches!

-Phil