This document contains information for an outdated version and may not be maintained any more. If some of your projects still use this version, consider upgrading as soon as possible.
Bundled within SilverStripe are default templates for any markup the framework outputs for things like Form templates,
Emails or RSS Feeds. These templates are provided to make getting your site up and running quick with sensible defaults
but it's easy to replace and customize SilverStripe (and add-on's) by providing custom templates in your own
mysite/templates folder or in your
Take for instance the
GenericEmail template in SilverStripe. This is the HTML default template that any email created
in SilverStripe is rendered with. It's bundled in the core framework at
Instead of editing that file to provide a custom template for your application, simply define a template of the same
name in the
mysite/templates/email folder or in the
themes/your_theme/templates/email folder if you're using themes.
$Body <p>Thanks from Bob's Fantasy Football League.</p>
All emails going out of our application will have the footer
Thanks from Bob's Fantasy Football Leaguee added.
As we've added a new file, make sure you flush your SilverStripe cache by visiting
Template inheritance works on more than email templates. All files within the
templates directory including
layout or anything else from core (or add-on's) template directory can be overridden by being located inside your
mysite/templates directory. SilverStripe keeps an eye on what templates have been overridden and the location of the
correct template through a SS_TemplateManifest.
The location of each template and the hierarchy of what template to use is stored within a SS_TemplateManifest
instance. This is a serialized object containing a map of template names, paths and other meta data for each template
and is cached in your applications
TEMP_FOLDER for performance. For SilverStripe to find the
it does not check all your
template folders on the fly, it simply asks the
The manifest is created whenever you flush your SilverStripe cache by appending
?flush=1 to any SilverStripe URL. For
example by visiting
http://yoursite.com/?flush=1. When your include the
flush=1 flag, the manifest class will search
your entire project for the appropriate
.ss files located in
template directory and save that information for later.
It will each and prioritize templates in the following priority:
- mysite (or other name given to site folder)
Nested Layouts through
SilverStripe has basic support for nested layouts through a fixed template variable named
$Layout. It's used for
storing top level template information separate to individual page layouts.
$Layout is found within a root template file (one in
templates), SilverStripe will attempt to fetch a child
template from the
templates/Layout directory. It will do a full sweep of your modules, core and custom code as it
would if it was looking for a new root template.
This is better illustrated with an example. Take for instance our website that has two page types
Our site looks mostly the same across both templates with just the main content in the middle changing. The header,
footer and navigation will remain the same and we don't want to replicate this work across more than one spot. The
$Layout function allows us to define the child template area which can be overridden.
<html> <head> .. </head> <body> <% include Header %> <% include Navigation %> $Layout <% include Footer %> </body>
<p>You are on a $Title page</p> $Content
<h1>This is the homepage!</h1> <blink>Hi!</blink>