2014-10-17 12:09:37 +02:00
|
|
|
title: SiteConfig
|
|
|
|
summary: Content author configuration through the SiteConfig module.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
# SiteConfig
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
The `SiteConfig` module provides a generic interface for managing site wide settings or functionality which is used
|
|
|
|
throughout the site. Out of the box this includes selecting the current site theme, site name and site wide access.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
## Accessing variables
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
`SiteConfig` options can be accessed from any template by using the $SiteConfig variable.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
:::ss
|
|
|
|
$SiteConfig.Title
|
|
|
|
$SiteConfig.Tagline
|
|
|
|
|
2014-11-11 15:44:37 +01:00
|
|
|
<% with $SiteConfig %>
|
2014-10-17 12:09:37 +02:00
|
|
|
$Title $AnotherField
|
2015-03-17 23:25:26 +01:00
|
|
|
<% end_with %>
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
To access variables in the PHP:
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
:::php
|
|
|
|
$config = SiteConfig::current_site_config();
|
2014-10-17 12:09:37 +02:00
|
|
|
|
|
|
|
echo $config->Title;
|
|
|
|
|
|
|
|
// returns "Website Name"
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
## Extending SiteConfig
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
To extend the options available in the panel, define your own fields via a [api:DataExtension].
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
**mysite/code/extensions/CustomSiteConfig.php**
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
:::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) {
|
2014-10-17 12:09:37 +02:00
|
|
|
$fields->addFieldToTab("Root.Main",
|
|
|
|
new HTMLEditorField("FooterContent", "Footer Content")
|
|
|
|
);
|
2011-02-07 07:48:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
Then activate the extension.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
**mysite/_config/app.yml**
|
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
|
|
|
|
2014-10-17 12:09:37 +02:00
|
|
|
<div class="notice" markdown="1">
|
|
|
|
After adding the class and the YAML change, make sure to rebuild your database by visiting http://yoursite.com/dev/build.
|
2015-03-17 23:25:26 +01:00
|
|
|
You may also need to reload the screen with a `?flush=1` i.e http://yoursite.com/admin/settings?flush=1.
|
2014-10-17 12:09:37 +02:00
|
|
|
</div>
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2015-03-17 23:25:26 +01:00
|
|
|
You can define as many extensions for `SiteConfig` as you need. For example, if you're developing a module and want to
|
2014-10-17 12:09:37 +02:00
|
|
|
provide the users a place to configure settings then the `SiteConfig` panel is the place to go it.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
## API Documentation
|
2014-10-17 12:09:37 +02:00
|
|
|
|
2015-03-17 23:25:26 +01:00
|
|
|
* `[api:SiteConfig]`
|