Try the beta version of the new SilverStripe documentation

For the next 2 weeks you can use the new documentation website and give us your feedback.

close

This document contains information about a future release and not the current stable version (3.1).

Be aware that information on this page may change and API's may not be stable for production use.

SiteConfig: Global database content

Introduction

The SiteConfig panel provides a generic interface for managing site wide settings or functionality which is used throughout the site. Out of the box it provides 2 fields 'Site Name' and 'Site Tagline'.

Accessing SiteConfig Options

You can access SiteConfig options from any SS template by using the function $SiteConfig.FieldName

$SiteConfig.Title 
$SiteConfig.Tagline
// or 
<% loop $SiteConfig %>
$Title $AnotherField
<% end_loop %>

Or if you want to access variables in the PHP you can do

$config = SiteConfig::current_site_config(); 
$config->Title

Extending SiteConfig

To extend the options available in the panel you can define your own fields via an Extension.

Create a mysite/code/CustomSiteConfig.php file.

<?php
class CustomSiteConfig extends DataExtension {
    private static $db = array(
        'FooterContent' => 'HTMLText'
    );
    public function updateCMSFields(FieldList $fields) {
        $fields->addFieldToTab("Root.Main", new HTMLEditorField("FooterContent", "Footer Content"));
    }
}

Then activate your extension in your [config.yml](framework/en/trunk/topics/configuration) file.

SiteConfig:
  extensions:
    - CustomSiteConfig

This tells SilverStripe to add the CustomSiteConfig extension to the SiteConfig class.

After adding those two pieces of code, rebuild your database by visiting http://localhost/dev/build and then reload the admin interface. You may need to reload it with a ?flush=1 on the end.

You can define as many extensions for SiteConfig as you need. For example if you are developing a module you can define your own global settings for the dashboard.

API Documentation

SiteConfig

Comments

Comment policy: Please use comments for tips and corrections about the described functionality.
Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant. Use the Silverstripe Forum to ask questions.

blog comments powered by Disqus