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.
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.
<?php
$a = new Area('Area Name');
$a->setBlockLimit(1);
$a->display($c);
?>This often used piece of code is great for site wide items such as navigation or footer areas.
<?php
$collectionc = $c->getCollectionID();
if ($collectionc == 1)
$collectionc = $c;
else
$collectionc = Page::getByID(1,'ACTIVE');
$area = new Area('Area Name');
$area->setBlockLimit(1);
$area->display($collectionc);
?>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;
$u->isLoggedIn()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 )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);
}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')?>" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css"
href="<?php echo $this->getStyleSheet('ie7.css')?>" />
<![endif]--> 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>';
}// Modify the separator in page titles.
define('PAGE_TITLE_FORMAT', '%1$s - %2$s');
// Turn on advanced permissions.
define('PERMISSIONS_MODEL', 'advanced');These two lines will make the login and 404 page use your default theme instead of the concrete5 one.
$v->setThemeByPath('/login');
$v->setThemeByPath('/page_not_found');I update the TinyMCE editor configuration with this snippit. I've set this up to be the most appropriate options for clients to use, removing things that are likely to cause issues.
theme : "concrete",
plugins: "inlinepopups,spellchecker,safari,advlink,paste",
editor_selector : "ccm-advanced-editor",
spellchecker_languages : "+English=en",
theme_concrete_buttons1 : "pastetext,pasteword,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,hr,|,formatselect",
theme_concrete_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,cleanup,code,forecolor,removeformat",
theme_concrete_blockformats : "p,address,pre,h1,h2,h3,div,blockquote,cite",
theme_concrete_toolbar_align : "left",
theme_concrete_styles: "Note=ccm-note",
spellchecker_languages : "+English=en"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