Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.


Discuss SilverStripe Widgets.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Can Widgets use $SiteConfig


4 Posts   691 Views

Matty Balaam

2 November 2011 at 5:04am (Last edited: 2 November 2011 5:06am), Community Member, 69 Posts


I'm making a simple widget to allow me to link to a page, with a simple description. This will only be on some pages.

To keep this in one area of the CMS so I can alter the text globally I have put the fields into CustomSiteConfig.

However, I can't get widgets to access the data using $SiteConfig.XX

If I put the same code directly into it works fine.


class CustomSiteConfig extends DataObjectDecorator {

function extraStatics() {
return array(

'db' => array(
'WidgetDescription => 'Text'
'has_one' => array(
'WidgetLink' => 'SiteTree'

public function updateCMSFields(FieldSet &$fields) {

$fields->addFieldToTab("Root.Main", new TextField('WidgetDescription', 'Widget Description'));
$fields->addFieldToTab('Root.Main', new TreeDropdownField("WidgetLinkID", "Widget Link", "SiteTree"));


Thank you for reading.


4 November 2011 at 6:49pm Forum Moderator, 5511 Posts

No I don't believe widgets can. They're encapsulated from the site from the looks of it.

If you want to access the SiteConfig you can add a function on your widget class that pulled it down

function SiteConfig() {
return SiteConfig::current_site_config();

Matty Balaam

4 November 2011 at 8:14pm Community Member, 69 Posts

Thanks Willr, I had got around this by using DataObject::get_one("SiteConfig"). I like to do things the "right" way if possible, so are there advantages to using the code you've posted?


5 November 2011 at 11:39am Forum Moderator, 5511 Posts

Checkout the code and you'll get a sense of what extra things it does (why you you should use it!)