2012-06-27 16:09:21 +02:00
|
|
|
# SiteConfig: Global database content
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
2012-03-09 21:34:05 +01:00
|
|
|
The `[api:SiteConfig]` panel provides a generic interface for managing site wide settings or
|
2011-02-07 07:48:44 +01:00
|
|
|
functionality which is used throughout the site. Out of the box it provides 2 fields 'Site Name' and 'Site Tagline'.
|
|
|
|
|
2011-03-08 22:05:51 +01:00
|
|
|
## Accessing `[api:SiteConfig]` Options
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2011-03-08 22:05:51 +01:00
|
|
|
You can access `[api:SiteConfig]` options from any SS template by using the function $SiteConfig.FieldName
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
:::ss
|
|
|
|
$SiteConfig.Title
|
|
|
|
$SiteConfig.Tagline
|
|
|
|
|
|
|
|
// or
|
|
|
|
|
2014-11-11 15:44:37 +01:00
|
|
|
<% with $SiteConfig %>
|
2011-02-07 07:48:44 +01:00
|
|
|
$Title $AnotherField
|
2014-11-11 15:44:37 +01:00
|
|
|
<% end_with %>
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
Or if you want to access variables in the PHP you can do
|
|
|
|
|
|
|
|
:::php
|
|
|
|
$config = SiteConfig::current_site_config();
|
|
|
|
$config->Title
|
|
|
|
|
|
|
|
|
2011-03-08 22:05:51 +01:00
|
|
|
## Extending `[api:SiteConfig]`
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
<?php
|
|
|
|
|
2011-04-15 11:35:30 +02:00
|
|
|
class CustomSiteConfig extends DataExtension {
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2012-06-28 11:43:56 +02:00
|
|
|
'FooterContent' => 'HTMLText'
|
|
|
|
);
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2011-10-28 03:37:27 +02:00
|
|
|
public function updateCMSFields(FieldList $fields) {
|
2011-02-07 07:48:44 +01:00
|
|
|
$fields->addFieldToTab("Root.Main", new HTMLEditorField("FooterContent", "Footer Content"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-11 15:44:37 +01:00
|
|
|
Then activate your extension in your [config.yml](/topics/configuration) file.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2013-03-27 12:06:57 +01:00
|
|
|
:::yml
|
|
|
|
SiteConfig:
|
|
|
|
extensions:
|
|
|
|
- CustomSiteConfig
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
|
2011-03-08 22:05:51 +01:00
|
|
|
This tells SilverStripe to add the CustomSiteConfig extension to the `[api:SiteConfig]` class.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2013-10-23 21:24:52 +02:00
|
|
|
After adding those two pieces of code, rebuild your database by visiting http://localhost/dev/build and then reload
|
2011-02-07 07:48:44 +01:00
|
|
|
the admin interface. You may need to reload it with a ?flush=1 on the end.
|
|
|
|
|
2011-03-08 22:05:51 +01:00
|
|
|
You can define as many extensions for `[api:SiteConfig]` as you need. For example if you are developing a module you can define
|
2011-02-07 07:48:44 +01:00
|
|
|
your own global settings for the dashboard.
|
|
|
|
|
|
|
|
## API Documentation
|
2014-11-11 15:44:37 +01:00
|
|
|
`[api:SiteConfig]`
|