Concrete5 – Blocks within Templates
Template that contains a block
When you create a new theme you sometimes need a custom autonav layout to make sure the navigation matches the theme. You can of course create a custom template and publish it somewhere. You could also create a Concrete5 package that puts everything into a single directory. But you would still have to select that custom template a few times.
As a theme create, you can actually create a theme that contains everything out of the box. No need for the user to add a navigation!
If you’re not familiar with the process of creating a theme, you should read this tutorial first: Create a Concrete5 Theme
We’re going to modify a template. It doesn’t matter which one you choose as long as there’s a little space left for a navigation. In this tutorial, we modify this template:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php defined('C5_EXECUTE') or die(_("Access Denied.")); $this->inc('elements/header.php'); ?> <div id="logo"> <a href="<?php echo DIR_REL?>/"><img src="<?php echo $this->getThemePath()?>/images/logo.gif" alt="Micropark Pilatus"/></a></div> <div id="menu"> <?php $nav = new Area('Navigation'); $nav->display($c); ?></div> <div id="nebenlinks"> <?php $sub_nav = new Area('Sub Navigation'); $sub_nav->display($c); ?></div> <div id="page"> <?php $content = new Area('Content'); $content->display($c); ?></div> <?php $this->inc('elements/footer.php'); ?> |
There are two area’s we’re going to replace “Navigation” and “Sub Navigation”. The users shouldn’t be able to modify anything within these areas.
The new template looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php defined('C5_EXECUTE') or die(_("Access Denied.")); $this->inc('elements/header.php'); ?> <div id="logo"> <a href="<?php echo DIR_REL?>/"><img src="<?php echo $this->getThemePath()?>/images/logo.gif" alt="Micropark Pilatus"/></a></div> <div id="menu"> <?php $bt = BlockType::getByHandle('autonav'); $bt->controller->displayPages = 'top'; $bt->controller->orderBy = 'display_asc'; $bt->controller->displaySubPages = 'none'; $bt->render('templates/header_nav'); ?></div> <div id="nebenlinks"> <?php $bt_links = BlockType::getByHandle('autonav'); $bt_links->controller->displayPages = 'top'; $bt_links->controller->orderBy = 'display_asc'; $bt_links->controller->displaySubPages = 'none'; $bt_links->render('view'); ?></div> <div id="page"> <?php $content = new Area('Content'); $content->display($c); ?></div> <?php $this->inc('elements/footer.php'); ?> |
- Line 9 – Instead of an area, we get the handle to our block. autonav in this case
- Line 10-12 – These are block specific settings we have to set. Unfortunately you have to look into the code to learn about these properties (until I publish a list of them)
- Line 13 – Output the block! The default template is called “view”. In this case we specified a custom template which we want to use. Whatever suits you!
The same thing again with our sub navigation on lines 22-26.
Done! When you now create a new page, it will always contain our navigations. And if you want to replace it, just edit your template or custom template. You’ll notice that once you’ve added a new page, you don’t see the “red rectangle” around the navigation area. The user can’t (doesn’t have to) edit the navigation anymore!
Please note – if you’re using a block template which has its own css file – it doesn’t get included automatically anymore! You must include it in your theme.
I showed you two different methods to add default content. Which one you choose depends on your needs and probably also on your background. If you have any further questions/problems with this tutorials, leave me a message and I’ll try to modify the tutorials if possible.
Pages: 1 2
8 Comments


on May 12th, 2009 at 16:18:40
Wie schaffe ich es, dass der Menüpunkt der aktuellen Seite hervorgehoben wird (active)?
on May 12th, 2009 at 16:23:27
Das ist abhängig vom Template. Im Standard-Template wird zum Beispiel die CSS Klasse “nav-selected” verwendet. Also ganz einfach im CSS eine Anweisung wie diese einfügen:
.nav-selected {
font-weight: bold;
}
on September 29th, 2009 at 17:12:39
Sprekenzie deutsch? No, not really, but I am learning C5 thanks to these tutorials. Thanks!
on September 29th, 2009 at 18:35:34
Here are the autonav attributes and values I found by looking at the code:
controller->orderBy = ‘display_asc’;
//$bt_links->controller->displayUnavailablePages = ‘false’;
$bt_links->controller->displayPages=’second_level’;
$bt_links->controller->displaySubPages = ‘none’;
$bt_links->controller->displaySubPageLevels = ‘enough’;
$bt_links->render(‘view’);
?>
‘orderBy’
‘display_asc’ - in their sitemap order
‘display_desc’ - in reverse sitemap order
‘chrono_desc’ - with the most recent first
‘chrono_asc’ - with the earliest first
‘alpha_asc’ - in alphabetical order
‘alpha_desc’ - in reverse alphabetical order
‘displayUnavailablePages’
?’true’/'false’? (not sure if value be quoted)
‘displayPages’
‘top’ - at the top level
’second_level’ - at the second level
‘third_level’ - at the third level
‘above’ - at the level above
‘current’ - at the current level
‘below’ - at the level below
‘custom’ - beneath a particular page
‘displaySubPages’
‘none’ - none
‘relevant’ - Relevant sub pages
‘relevant_breadcrumb’ - Display breadcrumb trail
‘all’ - Display all
‘displaySubPageLevels’
‘enough’ - Display sub pages to current
‘enough_plus1′ - Display sub pages to current +1
‘all’ - Display all
‘custom’ - Display a custom amount
‘render’
‘view’ – use default view
‘templates/custom_view’ – apply custom template
on November 8th, 2009 at 07:54:19
Die Zeilenangaben passen überhaupt nicht zum angezeigten Code.
Gruß
on November 8th, 2009 at 10:19:35
Hab’s korrigiert! Danke!
on June 1st, 2010 at 16:08:32
I used this method to modify the “full width” page type, adding a phone number above the navigation. But when I view the site following the update, the phone number is located below the navigation. If I go back to the “full width” template, the phone number is in the correct location. Why is it flipping positions on the child pages?
on June 3rd, 2010 at 09:40:17
I doubt that’s related to this block. You should probably use a forum and post a link to the site – it’s a lot easier to help you if it isn’t just about theory.