The content block in concrete5 is the main block used to place text content onto a page. In short, it gives you a nice HTML editor, saves the html of your formatted content and spits it back out on the page for display.

It's common practice to create 'block template overrides' for more complex blocks like the page list block and the autonav, but there are a few useful tricks I've discovered you can do by overiding the template for content block.

To override the content block's output we would copy /concrete/blocks/content/view.php to /blocks/content/view.php and edit this file.

Creating 'Shortcode' functionality (similar to Wordpress)

Wordpress has a feature where you can type in a 'code' into some content and it will be automatically replaced and processed.  These codes can do very complex things, but we can quickly replicate simpler shortcode functionality in concrete5 with a template override.

Say for example we wanted to display the current year on a page within some content (like a year in a copyright message). If we wanted this year to automatically update in some content, we could could use the following code as a template override:

<?php 
defined('C5_EXECUTE') or die("Access Denied.");
$content = $controller->getContent();
$year = date("Y"); 
print str_replace('[year]',$year, $content);
?>

All this does is look for the text [year] in some content and do a find and replace on it. A year is just an example, you could make this find and replace anything you wanted.

Read on for a more interesting use for this.

Coloured Bullet Points

One small limitation with CSS is that you can't easily colour the actual bullet points for lists items differently from the text without extra markup.

To make this easier, we can do something like this in our template override:

<?php 
defined('C5_EXECUTE') or die("Access Denied.");
$content = $controller->getContent();
print str_replace( '</li>', '</span></li>', str_replace('<li>', '<li><span>', $content));
?>

This just wraps list item contents with an extra span tag. This means we can then easily style the list items and the contents with different colours, e.g.:

.mainarea ul li {
color: #EE4D31;
}

.mainarea ul li span {
color: #000;
}

So now, anytime lists are added in content blocks, they'll be nicely styled with coloured dot points (see example), without needing to do anything special in the content editor.

You wouldn't want to get too carried away with the above technique and cram too much processing into the template, but it's handy for some find and replace purposes.

-Ryan