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.

Post sort order: Post Date (Newest First) | Post Date (Oldest First) | Alphabetical | Date Updated

Prefix img src assets with a leading slash in SilverStripe

Posted 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.

Populate defaults dynamically with SilverStripe

Posted in SilverStripe -

SilverStripe allows default values to be set for fields on data objects using the static $defaults property but this cannot be populated with dynamic values, such as using date() or rand(). Instead use the populateDefaults() function.

SilverStripe cache directory

Posted in SilverStripe -

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.

How to log into SilverStripe if you've lost the login details

Posted in SilverStripe -

If you have lost the admin login details for a SilverStripe installation and sending an email to reset the password is not working, there is a default admin account that can be enabled. After logging in, reset the regular administrator's details and then remove the temporary login as shown in this post.

.htaccess condition to prevent missing CSS, JS, image urls being parsed by SilverStripe

Posted in Apache and SilverStripe -

The default .htaccess file for SilverStripe runs all URLs that do not belong to actual files on the filesystem through the Sapphire framework. This means that if a request is made for a CSS file that does not exist, for example, it will be run through SilverStripe/Sapphire, which is not really necessary.