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.

Widgets /

Discuss SilverStripe Widgets.

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

$SiteConfig.XX in Widget template?


Go to End
Reply


10 Posts   2054 Views

Avatar
socks

Community Member, 190 Posts

9 March 2011 at 5:07pm

Edited: 03/11/2011 4:32am

Is it possible to pull something from $SiteConfig and display in a Widget template? I can't get it to work. Only other thing I could think of to try was using:
<% control Top %> $SiteConfig.XX <% end_control %>

Thanks

Avatar
Matty Balaam

Community Member, 69 Posts

3 November 2011 at 1:28am

Edited: 03/11/2011 4:32am

Did you manage to find a solution to this?

I have got around this before using a data object, but surely it should be possible out of the box?

Avatar
swaiba

Forum Moderator, 1799 Posts

3 November 2011 at 2:57am

Edited: 03/11/2011 4:32am

could do something like this in a function int he widget controller?

   $doSiteConfig = DataObject::get_one('SiteConfig');
   return $doSiteConfig->SomethingInSiteConfig;

Avatar
Matty Balaam

Community Member, 69 Posts

3 November 2011 at 6:44am

Edited: 03/11/2011 6:45am

What I have found to partly work is this:

   public function SiteConfigInWidget () {
      return DataObject::get_one("SiteConfig");
   }

   

I can then either use a control block or $SiteConfigInWidget.XX to get the info. This works fine and as expected.

HOWEVER, if I then have another widget below this one, which also tries to get a dataobject, the first time I use a control block or $SiteConfigInWidget2.XX I get no result. The second time, however, I do.

Running a $SiteConfigInWidget2.Debug in the template gives me the following for the first time:

Name:SiteConfigInWidget2
Table:
Value:

Am I just being stupid here? Have I missed something out?

I'm still wondering why I can't just used $SiteConfig however. Is this expected, or a bug in Silverstripe?

Avatar
swaiba

Forum Moderator, 1799 Posts

3 November 2011 at 7:01am

This is not a bug, it is a question of context/scope.

When you are in the page contect you get the contentcontroller (search "function SiteConfig" in saphire to find the function. When you are in teh widget you are in the WidgetController - two different contexts.

Avatar
Matty Balaam

Community Member, 69 Posts

3 November 2011 at 7:05am

Ah I see.

It's a shame you can't access SiteConfig by default though, as it does (to me at least) seem like a natural place to keep side-wide info.

Regarding my other problem, I've tried that on a different Silverstripe site and i can't replicate the problem, so there must be something else going on.

Avatar
Matty Balaam

Community Member, 69 Posts

3 November 2011 at 7:57pm

I managed to fix the problem above.

In my WidgetHolder.SS I just had

$Content

However, it seems that $Content needs to be in a uniquely named div, so this did the trick:

<div id ="$ClassName">
   $Content
</div>

Thank you for your help earlier swaiba.

Avatar
socks

Community Member, 190 Posts

2 December 2011 at 5:06pm

Not sure why I didn't think of that, thank you Matty :-)

Go to Top