To develop websites I'm a big fan of Panic's Coda. It's a great editor, with lots of well designed built in functions. It, like many other text editors, includes a 'clips' function that stores regularly used pieces of code. I use this feature to store small snippets of code that helps me put together a specifically configured Concrete5 website quickly.

Below is my growing list of C5 clips. If you're a developer that uses Concrete5, these may be useful to you.

New Editable Area

Add a new editable area to a page template. By default, I include the setBlockLimit line as more often than not I want to restrict the number of blocks that can be added to an area.

$a = new Area('Area Name');

Test if in edit mode

A basic one to test if the page is currently in edit mode (to be able to add extra classes to divs for example), but this snippit is more so to remind me that I need to make $u global first.

global $u;

Check if in edit mode or if an area has any blocks

This is a very useful check when you want to hide a block when nothing is in it, but still be able to put something in it when you go into edit mode.

if ($c->isEditMode() || $a->getTotalBlocksInArea($c) > 0 )

Automatically display a resized image

This snippit outputs an img tag for a resized image from a page attribute.

$im = Loader::helper("image");
if ($c->getAttribute('image')) {
    $im->outputThumbnail($c->getAttribute('image'), 160, 160);

Add Internet Explorer conditional stylesheets

On the occasions where Internet Explorer needs a styling kick in the right direction, this snippit adds correctly linked stylesheets, nested within conditional statements.

<!--[if IE 6]>
    <link rel="stylesheet" type="text/css" 
        href="<?php echo $this->getStyleSheet('ie6.css')?>" />
<!--[if IE 7]>
    <link rel="stylesheet" type="text/css" 
        href="<?php echo $this->getStyleSheet('ie7.css')?>" />

Include the site's page name automatically, allowing it to be overridden

On some sites, it makes sense to automatically display the page name as a page title. This checks to see if there is a page attribute, in this case 'extended_page_title', and if present uses that instead, allowing you to override the header if you wish.

$page = Page::getCurrentPage();		
if ($page->getCollectionAttributeValue('extended_page_title') != '') {
    echo '<h1  id="page-title">' . 
         $page->getCollectionAttributeValue('extended_page_title') . '</h1>';
} else {
    echo '<h1 id="page-title">' .  $page->getCollectionName() . '</h1>';

To be placed in config/site.php

// Modify the separator in page titles. 
define('PAGE_TITLE_FORMAT', '%1$s - %2$s');
// Turn on advanced permissions.
define('PERMISSIONS_MODEL', 'advanced');

To be placed in config/site_theme_paths.php

These two lines will make the login and 404 page use your default theme instead of the concrete5 one. 


These are the snippets of code that I have in my clips list at the moment. For handy reference I really like Weblicating's C5 Cheat Sheet (which some of the above snippits are also likely to be on).

- Ryan