Category: SilverStripe

Information, tutorials, code tips and how tos for programming the SilverStripe CMS

SilverStripe is a free open source content management system that is coded in PHP and supports MySQL, Microsoft SQL Server and Postgres as database backends. It contains the Sapphire model-view-controller framework and is extremely extendable. There are a number of modules, themes and widgets abailable and it is easily customisable. The admin interface is slick and can also be customised with additional tabs and fields depending on the page types.

Be sure to check out the online documentation and The latter is full of all sorts of useful tips and tricks and is worth spending time looking through after reading the docs.

Different home page and sub pages with SilverStripe

The SilverStripe CMS makes it very easy to have a slightly different layouts between pages by creating another page type and using $Layout with different layout templates. I did this for the Fabco Ltd website which is a small website with a larger main image on the homepage and a smaller version of this image on the subpages; in all other respects the templates are the same.

Example website

The example website used in this post is Fabco Ltd. I’ve also included two screenshots below showing the homepage and subpage with the different main image.


fabco ltd's homepage


contact page on the fabco website

How to set up slightly different templates with SilverStripe

Create a new file at mysite/code/HomePage.php like so (it doesn’t need anything else in it):

 class HomePage extends Page {
 class HomePage_Controller extends Page_Controller {

In the main content area of the file at /themes/theme-name/templates/ change $Content/$Form section to include $Layout like so (obviously the id and class of the containing <div> may be different for your template):

<div id="content" class="typography">

At /themes/theme-name/templates/Layout create two files: and; these contain the slightly different layouts that will go where $Layout is in the above file.

For the Fabco website looks like this:

<img id="mainpic" src="/themes/fabco/images/home.jpg" width="770" height="404" alt="fabco ltd" />

and like this:

<img id="mainpic" src="/themes/fabco/images/subpage.jpg" width="770" height="108" alt="fabco ltd" />

Then open the following URL in your web browser to rebuild the database etc, changing “mysite” to the domain name of the site:


Now go to the CMS admin and change the page type of the home page to “Home Page” under the “Behaviour” tab as shown in the screenshot below.

modifying the page behaviour in silverstripe

The home page now has a ever so slightly different layout to the other pages. Easy.

Read More »

Prefix img src assets with a leading slash in SilverStripe

When inserting an image into the TinyMCE HTML editor in SilverStripe it doesn’t prefix the src attribute of the img tag with a leading slash leaving it like e.g. src="assets/images/myimage.jpg". This is acceptable because it writes out a <base> tag into the document <head> so these relative urls are made into absolute URLs using the href in the base tag. However, as I have found, some bots ignore the base tag and are unable to grab the images correctly. This post shows how to modify your base page class in SilverStripe to prefix assets with a leading slash.

Read More »

SilverStripe cache directory

SilverStripe by default creates a directory for caching the site manifest etc by using the PHP function getSysTempDir(). It is possible to locate this directory elsewhere by simply creating a directory called silverstripe-cache in the website’s root directory, or at any other location by setting the TEMP_FOLDER constant.

Read More »