SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Tutorials - Big bits of code to help you do more

Working with Site Config


One of the great new features of 2.4 is the introduction of a Site Config page. This allows you to put all of those fields which are not page related, such as The sites title, root access permissions and even the current theme. The SiteConfig class is simply a dataobject and so can easily be extended to include fields, relationships and functions which you can then access from anywhere in your site.

Accessing items in your SiteConfig is as easy as preceding each item with $SiteConfig. For example this would display the Title field:


Or alternatively:

<% control SiteConfig %>
<% end_control %>

Accessing SiteConfig from the Controller

So accessing it from the template is super simple and so it turns out is accessing it from a Controller:


Or alternatively if you are in a class that does not descend from ContentController:


Customizing SiteConfig

So of course there's not much point in the SiteConfig unless we can add or own fields, relationships and functions. To do so we use the DataObjectDecorator class which allows us to 'decorate' other classes with fields, functions and relationships. We need to decorate SiteConfig instead of extend it with our own class because the core SiteConfig class is the one that SilverStripe will look for. Here is an example of a CustomSiteConfig class which extends DataObjectDecorator:


class CustomSiteConfig extends DataObjectDecorator {
	function extraStatics() {
		return array(
			'db' => array(
				'Spiel' => 'Text'
			'has_one' => array(
				'SiteLogo' => 'Image'
	public function updateCMSFields(FieldSet &$fields) {
		$fields->addFieldToTab("Root.Main", new TextareaField("Spiel"));
		$fields->addFieldToTab("Root.Main", new ImageField("SiteLogo", "Logo"));
	public function getPooSpiel(){
		return '<h3>Poo!</h3>' . $this->owner->Spiel;

So here we are adding an extra field to $db and a $has_one relationship. We then add the appropriate form fields to the CMS and we also define a new function. The function is not particularly useful in this case and simple adds the header 'poo' to the start of our Spiel field. However, notice that we use $this->owner to refer to the Spiel field. This is the syntax you must use when extending a DataObject using the DataObjectDecorator so that SilverStripe refers to the object that is being extended rather than the Extention class it self.

Now in order to get SilverStripe to register this extention we need to add this line to our _config.php:

DataObject::add_extension('SiteConfig', 'CustomSiteConfig');

Now in our template we can use these new fields like so:


<% control SiteConfig.SiteLogo %>
<% end_control %>

So there you have it, the new SiteConfig. Very useful and easy when you know how! :)

Thanks to Johannes Fischer for suggesting this post.

Special Thanks

Special thanks go to Frank Mullenger for their contributions to this post.

Aram Balakjian avatar

Aram Balakjian

Aram is a web developer running London based agency Aab Web. He has a strong passion for developing attractive, usable sites around the SilverStripe CMS.

  • Quinten
    11/10/2010 6:12pm (7 years ago)

    Thanks, this comes in very handy. Didn't know about the SSbits site since today, seems to be very useful for my silverstripe project!!!!

  • Frank Mullenger
    27/10/2010 9:14pm (7 years ago)

    Is there any way for the dataobjectmanager to be used in the site config?

  • MRKDevelopment
    02/12/2010 4:22am (7 years ago)

    This is great, just what I was looking for. AWESOME.

  • Aram Balakjian
    02/12/2010 1:59pm (7 years ago)

    @Framk Mullenger - I was under the impression that DOM was now working in SiteConfig, I know UC applied a patch a while back? There was an old hack to make it work here:

    @MRKDevelopment - Glad it was useful for you :)

  • aragonne
    09/12/2010 9:51am (7 years ago)

    Hi Aram, Thanks for the great tutorial. Do you know how to set default values for the site config fields ... similar to the static $defaults array for DataObjects?

    I tried using static $defaults in my SiteConfig extension but the values didn't get set.


  • Frank Mullenger
    21/12/2010 12:41am (7 years ago)

    @Aram Thanks, btw the line: ContentController::SiteConfig() should probably be ContentController->SiteConfig() or SiteConfig::current_site_config().

  • Aram Balakjian
    23/12/2010 12:36pm (7 years ago)

    Thanks Frank, amended! :)

  • Don St. Troy
    12/01/2011 10:12pm (6 years ago)

    This is a necessary tutorial for those using Silverstripe

  • Allan Mercado
    16/02/2011 12:00am (6 years ago)

    Hi Aram,

    Great tutorial, thanks!
    I'm using staticpublisher for a site where I'm using this idea. And I'd like to be able to regenerate the static pages when the new SiteConfig is saved.
    Is there a callback or anything that could alert me when the user clicks save on this custom Site Config?


  • juneallison
    22/07/2011 3:59pm (6 years ago)

    What would I need to change in this example to make the new fields appear in a new tab?

    And out of curiosity why do you use "public function updateCMSFields(FieldSet &$fields)" instead of something like "function getCMSFields() {
    $fields = parent::getCMSFields();" ?

    Thanks for your help!

  • ilovemoon
    17/08/2011 4:02pm (6 years ago)

    Hi Aram,
    I was using the CustomSiteConfig to control content in the footer.

    When I went to test the cms as a 'content author' the footer content was editable but not saveable.
    There was no save button.

    Is the CustomSiteConfig only editable by administrators or is there something i can do to allow the content authors to edit also?

    Thanks, and thanks for ssbits too, it's been a great help :)

  • Aram Balakjian
    17/08/2011 4:04pm (6 years ago)

    Hi ilovemoon,

    There should be a permission in Security 'Edit Site Config' which will allow other groups to edit it :)


  • ilovemoon
    17/08/2011 5:03pm (6 years ago)

    ah yes... 'Manage Site Configuration' Thank you so much :)

  • Had
    29/12/2011 11:06pm (6 years ago)

    Hi Aram,
    Thanks for this great tutorial, as ever...
    I've some troubles to have some nested tabs within the $fields parameters.
    How could I do somethings like this :
    $fields->addFieldToTab("Root.News" ,
    new TextField("NewsTitle"));

    $fields->addFieldToTab("Root.News.Image" ,
    new ImageField("NewsImage"));

    I've tried to add a TabSet like that :
    new TabSet("Image"));
    But it faill. I also try to add a TabSet on the Root directly, with no success.

    Thanks for your help,
    Hadrien (CH)

  • Aram Balakjian
    30/12/2011 9:58am (6 years ago)

    Hi Had,

    try this:

    new TabSet('Content')

    That should give you a new tabset on the root, which you can then add sub tabs to using addFieldToTab().


  • Had
    30/12/2011 5:27pm (6 years ago)

    Thanks a lot Aram, it's works perfectly !

  • Tobias Ebert
    21/06/2012 11:22pm (5 years ago)

    Hey Aram,

    I've successfully integrated the DOM in the SiteConfig. My Problem is that I cant loop through the items in the templates. All my entries in the SiteConfig are saved, if I can trust that CMS message :).

    Here is my CustomSiteConfig.php
    class CustomSiteConfig extends DataObjectDecorator {

    function extraStatics() {
    return array(
    'db' => array(
    'has_one' => array(
    'has_many' => array(
    'PromoItems' => 'GlobalPromoItem',
    'InfoItems' => 'GlobalInfoItem'

    public function updateCMSFields(FieldSet &$fields) {

    $fields->findOrMakeTab("Root.GlobalContent", "Globale Contents");

    $globalInfoItems = new ToggleCompositeField ("globalInfoItems","Infoboxes",
    new Fieldset(
    $manager = new DataObjectManager(


    class GlobalInfoItem extends DataObject
    static $db = array (
    'Headline' => 'Text',
    'Description' => 'Text',
    'Title' => 'Text',
    'UrlParam' => 'Text'

    static $has_one = array (
    'Pic' => 'Image',
    'SiteConfig' => 'SiteConfig'

    static $summary_fields = array(
    'Headline' => 'Title',
    'Description' => 'Description',
    'UrlParam' => 'URL',
    'Pic.Url' => 'Image'

    public function getCMSFields_forPopup()
    return new FieldSet(
    new TextField('Headline', 'Überschrift'),
    new TextField('Description', 'Title'),
    new TextField('Title', 'Description'),
    new TextField('UrlParam', 'URL'),
    new ImageField('Pic', 'Image')

    <% control SiteConfig.InfoItems %>
    <% end_control %>

    Also tested:

    <% control SiteConfig %>
    <% control InfoItems %>
    <% end_control %>
    <% end_control %>

    but without any success! Maybe and hopefully you guys have an idea where the problem is, thanks for any help in advance.

  • Tobias Ebert
    21/06/2012 11:24pm (5 years ago)

    i dont get any error msg, neither any result :(

  • Tobias Ebert
    21/06/2012 11:36pm (5 years ago)

    mhm i tried a bit more and found out that


    is necessary, now i can retrieve the items in the control loop :D

  • ilovemoon
    09/07/2012 4:28pm (5 years ago)

    Hi Aram,
    I recently returned to a site I hadn't touched in a few months and it seems I can no longer save the site config area. I can make changes to the fields but when I click save the save icon just keeps spinning. Firebug gives me "NetworkError: 404 Not Found -"
    Any thoughts on this or why it's happening now? I can edit and save the rest of the site.

Post a comment ...

You cannot post comments until you have logged in. Login Here.


Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image wfacewomens
3 article image Daniel Hensby
4 article image Marcus Dalgren
5 article image ryduhartchas
6 article image Hamish Campbell
7 article image Ty Barho
8 article image Martijn van Nieuwenhoven
9 article image Darren-Lee
10 article image Roman Schmid

View full leaderboard