SilverStripe 2.4 Module Extension, Themes, and Widgets: Beginner's Guide

By Philipp Krenn
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Principles and Concepts

About this book

HTML, CSS, JavaScript, PHP, databases, frameworks, CMS, and many other fast-evolving technologies make up modern web-development. How can you effectively create stunning results without being limited by the ease of your tools? That's where SilverStripe CMS comes into play.

SilverStripe, with its simple and intuitive design, is easy to work with and offers numerous customization opportunities. But understanding the options available and getting hands-on with the development techniques is not a piece of cake and certainly not a delightful experience if you're relying on tutorials and documentation available online.

Silverstripe 2.4 Module Extension, Themes, and Widgets: Beginner's Guide takes you through designing catchy and flexible templates, adding powerful features effortlessly, integrating everything into an intuitive backend for easy administration in a simple way, and implementing nifty features with minimal effort. From the most basic to complex forms, from simple to sophisticated pages, you'll learn how to get the most out of your SilverStripe application. SilverStripe keeps everything nice and simple, but if you need to, you can extend and customize every part of it. Graphic examples illustrate the general principle of operation, gradually introducing the finer details needed to get professional results. Common requirements such as image galleries, site search, and more can be reused or extended to fulfill your needs.

The author's experience in designing and developing SilverStripe projects enables him to share insights on creating professional web applications in a clear and friendly way.

You will start off with creating your own templates – covering the general layout, while also taking search engine optimization into consideration. Next, you will look at the logic driving your web application, and the database. Using these basic concepts, you will start building more advanced features. These include the integration of Google Maps, Twitter and Facebook, image galleries, the handling of user-supplied information, your own full-text search, and more. Finally, you'll even translate and internationalize your project. All of this can be easily achieved with SilverStripe.

All of this and quite a bit more is covered by Silverstripe 2.4 Module Extension, Themes and Widgets: Beginner's Guide. Besides general principles, the focus is on reusable code – getting your project started in no time.

Publication date:
May 2011


Chapter 1. Principles and Concepts

Whether you have already worked with other content management systems (CMS) or you are a newcomer to this area, SilverStripe's approach and specific feature set will show you something new. It's a flexible and powerful tool for creating both websites and web applications — catering to the requirements of highly customized or out-of-the-box installations.

In this chapter we'll take a short look at:

  • Why you should use SilverStripe

  • How the basic principles and approach of the system work

  • What the general file structure looks like

  • What additional resources are available and what to expect from the general ecosystem

As we explore SilverStripe, we will develop a single example project throughout this book. We'll create a website for a bar, enabling the owner to edit various pieces of content himself, including opening hours, prices, and photos. The page will also provide a gallery, contact form, and other interactive parts. Starting with the second chapter, we'll gradually add more and more features and get to know the inner workings of SilverStripe. Later on, we will cover advanced topics such as translating the site, easily managing user data, and sending newsletters.

In case you haven't installed SilverStripe, see the Appendix for detailed instructions. In our example we'll assume that you already have it up and running. Additionally, we won't go into depth explaining the CMS's basics as it's pretty straightforward and well documented. We'll talk about the documentation and support a little later in the chapter.


Why SilverStripe

Whether you were attracted by the "sexy" CMS backend (if you haven't already taken a look at it, you can do so at or the unique set of features, let's take a short look at some of the most notable characteristics. While some parts might not make a lot of sense or seem appealing at first, you're sure to love them later on.

CMS and framework

SilverStripe actually consists of two parts, planned and developed together by the same group of people: the SilverStripe CMS and the Sapphire Framework. Today there are many content management systems and a fair few programming frameworks available. However, SilverStripe's concept of tightly coupling them is a rare but extremely powerful approach. You get the best of two "worlds" and don't need to select one over the other.

This coupling also targets the needs of the two main user groups of the system: developers use the framework to build websites and web applications, whereas content editors rely on the CMS backend.


SilverStripe is a modern system and therefore the code quality is higher than the common perception of PHP products. This also means it can take advantage of newer features in PHP. The benefit of this is that the code you write can be more logical, succinct, and easy to write and change. SilverStripe is not the only modern PHP application in this sense, but this newness does substantially diferentiate it from large, established CMS projects written in PHP and other languages.

Assume you have a simple project with a single developer, Alice and one content editor, Bob.

Alice loves to work with code, and Sapphire enables her to focus on writing HTML, CSS, JavaScript, and (object-oriented) PHP. She is not limited by a graphical interface or the need to study one, but can use the raw power of programming to build complex systems quickly and robustly. In fact, the developer is required to rely on programming in Sapphire as there is no such interface. Although a graphical configuration interface might sound more appealing at first, we'll show you how to achieve more powerful configurations with a few lines of code in our example project. Bob on the other hand doesn't know anything about programming, but there's no need for him to do so. Using the intuitive CMS he can access and edit any content without ever having to leave the graphical interface. This lowers the entry barrier and enables editors like Bob to efficiently work with SilverStripe, only requiring minimal training.

Openness and interoperability

SilverStripe is a strict supporter of the open source movement. It's even seen as one of the main reasons for its success. Source code, updates, documentation, and more are provided free of charge, and everyone is encouraged to actively participate wherever they see fit.


SilverStripe is released under the Berkeley Software Distribution (BSD) license, a permissive license model originally developed by the University of California, Berkeley. It allows you to copy, modify, and distribute software, even commercially, without having to grant access to the modified source code as long as the original license stays in place. That means you can create your own extensions for paying customers without having to release your changes; most other CMS don't allow this. The BSD license can be found at

Interoperability is another virtue of SilverStripe. Its core technologies (PHP, MySQL, JavaScript, HTML, and CSS) are open standards, widely used, easy to learn and likely to last for many years. A lot of work has gone into supporting all major browsers and operating systems, different web servers and databases, multiple languages and character sets, accessibility, and more.

Getting your job done

We won't go into too much detail, but here's a brief overview of what developers should expect and how things are done in "SilverStripe land":

  • Like in any good web application framework, HTML, PHP, and database queries are not mixed but nicely separated in three layers: one for storing information in the database, one containing the logic, and one responsible for the output. This really helps keep the code clean and easy to maintain.

  • The database layer is abstracted so you don't need to care for various quirks of the different databases. MySQL, PostgreSQL, SQLite, and Microsoft SQL Server are fully supported; an Oracle module is currently being worked on and is marked as experimental. Changes to this layer are also synchronized with the database, saving you from making manual changes in various places.

  • Customization is achieved through class inheritance, this helps to avoid repetition. Consider our developer Alice and content editor Bob. We could say that both are a "person", having a name, sex, age, and so on. "Developers" additionally have skills like programming languages, while "content editors" don't. Relying on inheritance we could model the entity "person" once and only add specific attributes to the so-called sub classes of "developers" and "content editors" as needed; without having to repeat the basic person information multiple times. This approach is common in programming frameworks, but it's rare for a CMS to support it. The bigger and more complex your system gets, the more this principle will shine as we'll see later on.

  • SilverStripe's core can be extended by modules (adding functionality, such as a blog), themes (giving your project a different look), and widgets (including small features, such as a map on a contact page).


The file structure

Let's take a look at the file structure. We'll assume you've just installed the latest version successfully, so you should see the following:


This folder contains all the files uploaded by website and CMS users. Content editors can access any file under the Files & Images menu point in the CMS backend. Keeping all user files in a single place has two advantages:

  • Having a clean file structure

  • Being able to limit SilverStripe's write permissions to this folder


All the files located here are used to power the CMS interface. We won't be changing any of these.


This is a module for rendering your page's sitemap in XML, which improves the communication with search engines. We'll talk more about that in the next chapter. If you don't need this feature you could remove the folder to get rid of it.


Note that modules in SilverStripe are always located in the root folder.


This folder contains our custom PHP and JavaScript code. Its default name is mysite/, but you can also rename it, if you want to. We'll take a look at that in chapter three.

Actually, mysite/ is a module itself, extending the base system according to our requirements. This folder is the core of any customization. Like in any other module, there is a mysite/_config.php file, which contains the site's configuration. This includes the database credentials and much more, as we'll see.


This is the heart of your application as it contains the Sapphire framework. The other parts of the system rely on the core classes contained in this folder.


Although the mysite/ folder accommodates our custom logic, this folder houses our site's layout — consisting of template, CSS, and image files. This directory can contain multiple theme subfolders. By default, these include the standard theme BlackCandy.


SilverStripe's ecosystem

SilverStripe is a very powerful tool, supported by a whole ecosystem. Let's take a quick look at it so you can make the most of it.

The company behind SilverStripe

While SilverStripe is open source software, the source code is managed and mainly produced by a privately held company, SilverStripe Ltd.. The headquarters are in New Zealand, but there's also a branch in Australia.

This is unusual as most open source projects are developed and maintained by a community without a company in the background. In this case, however, it does not mean that there is a limited, free community edition and a full, commercial one; there is only a single, free version with all the features SilverStripe Ltd. itself uses for its commercial projects.

Based on this model, you actually get the best of two worlds: on the one hand you can freely access the source code, documentation, roadmap, and bug tracker. On the other hand you can easily get commercial support, or the development of whole projects, from the main SilverStripe developers themselves. That's a huge selling point as help is always only a phone call away and you don't have to rely on someone's goodwill to help you. Enterprise-level organizations are likely to require such a support system before even considering making use of specific software.

For more details on the company and the professional services that they provide, visit Source code, documentation, and much more is available on


SilverStripe provides a vast amount of freely available documentation. While this book will cover many different topics and provide you with all the tools needed to accomplish common tasks, it can never include every little detail. And as the development never stops, some features of SilverStripe might change, but such changes will be included in the documentation.

For an overview of all the available resources, head over to

User help

In order to get to know the nuts and bolts of the CMS take a look at We'll not cover that part in the book as it is very well documented and mainly self-explanatory. It is also available from within the CMS through the Help button.

Developer documentation wiki holds the official documentation, including information on how to install SilverStripe, how to get started, and some more advanced topics. Some articles are more comprehensive than others. This book will cover all the basics and most of the details documented there.

API documentation

If you are an advanced user, which you will definitely be by the end of this book, you'll be most interested in the Application Programming Interface (API):

While the documentation covers specific tasks step by step, the API describes how specific functions can be called, how they interact, and how to use them in a concise and technical fashion.

The API covers all the available parts of Sapphire, the SilverStripe CMS, and modules created by the core developers.


If you're stuck with a problem or need some advice on how to accomplish a task, don't hesitate to get in touch with the community (for example, if you have problems installing the CMS). It's an ever-increasing pool of like-minded people, actively discussing problems and helping each other. It consists of four main communication channels, detailed below.

Forum is the official SilverStripe forum, which is a good place to ask general questions as well as get help with specific problems. The response time ranges from minutes to hours, depending on the time of day you post a question. The core developers visit the forum frequently, so you can generally expect helpful responses by them or other community members. Additionally, when you sign up to the forum, you can subscribe to a monthly SilverStripe community newsletter.

IRC chat

IRC is the quickest way of getting help. Depending on the time of day you might have just a few or up to dozens of communication partners. It's especially useful for asking rather simple and short questions and the core developers are also frequently available.

The server used is and the channel #silverstripe — for more details, web based access, or logs, head over to

Development mailing list is the place to discuss the general direction and decisions concerning SilverStripe's development. It's a good place to find out what's new and currently under development.

Bug tracker

Here you can see the roadmap of the project, review the changelogs, or report bugs you have found:


If you're a Twitter user, you can follow @silverstripe for the latest updates. The commonly-used hashtag is #silverstripe.



We've already learned quite a lot about the general principles of SilverStripe and its ecosystem, specifically:

  • Why SilverStripe is unique and distinct from other CMSs and frameworks

  • Which basic principles are used throughout the system

  • Which folders are available in general and what they are used for

  • How SilverStripe is developed and why it's useful to have a company behind an open source project

  • What resources are available, where to find documentation, and how to get help

In the next chapter, we'll build upon the general concepts we've learned so far by exploring SilverStripe's template engine. This will enable you to create and style the interface of our example project.

About the Author

  • Philipp Krenn

    Philipp Krenn lives in Vienna, Austria and studies software engineering. Besides being a student, he also works as a freelance IT trainer and web developer (mostly using SilverStripe, but also some Drupal, CakePHP, and Smarty). Philipp started using SilverStripe in 2007 while he was one of the students at the Google Summer of Code improving the project. While kicking off the effort to support multiple databases (besides MySQL), he got a good insight into the inner workings of the project. Building on top of that, he became an expert in developing web applications with SilverStripe.

    Browse publications by this author
SilverStripe 2.4 Module Extension, Themes, and Widgets: Beginner's Guide
Unlock this book and the full library for FREE
Start free trial