753 Posts in 312 Topics by 289 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 376 Views |
-
Can Widgets use $SiteConfig

2 November 2011 at 5:04am Last edited: 2 November 2011 5:06am
Hi,
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 page.ss it works fine.
<?php
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.
-
Re: Can Widgets use $SiteConfig

4 November 2011 at 6:49pm
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();
} -
Re: Can Widgets use $SiteConfig

4 November 2011 at 8:14pm
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?
-
Re: Can Widgets use $SiteConfig

5 November 2011 at 11:39am
Checkout the code and you'll get a sense of what extra things it does (why you you should use it!)
https://github.com/silverstripe/sapphire/blob/2.4/core/model/SiteConfig.php#L153
| 376 Views | ||
|
Page:
1
|
Go to Top |


