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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS3 - Accessing SiteConfig values in Widget class

Go to End

2 Posts   877 Views


Community Member, 48 Posts

17 September 2012 at 1:10pm

I'm having issues getting hold of values stored in my SiteConfig from within my widget class. I searched around and found people suggesting I should be able to access the config through SiteConfig::current_site_config() but when I try and implement this, I get an error:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in /...../widgets_facebookFeed/FacebookFeedWidget.php on line 3

class FacebookFeedWidget extends Widget{
	static $thisConfig = SiteConfig::current_site_config();
	static $title = "";
	static $cmsTitle = "Facebook Feed Widget";
	static $description = "This widget shows the Facebook feed";

	static $db = array(
		"FacebookURL" => "Text"
	static $defaults = array(
		"FacebookURL" => $thisConfig->FacebookURL

	function getCMSFields(){
		return new FieldList(
			new TextField("FacebookURL", "Facebook URL")
	function getFacebookURL(){
		$output = new ArrayList();
			new ArrayData(
					"FacebookURL" => $this->URL
		return $output;

What am I doing wrong here?


Community Member, 46 Posts

18 September 2012 at 7:46am

The Problem is this line:

static $thisConfig = SiteConfig::current_site_config();

In PHP, it is not possible to initialize a static constant with the result of a function call (i.e. you are not allowed to call a function there). You will have to set the default value in some other way (or at a different point in your code).