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   1981 Views

Avatar
socks

9 March 2011 at 5:07pm (Last edited: 3 November 2011 4:32am), Community Member, 190 Posts

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

3 November 2011 at 1:28am (Last edited: 3 November 2011 4:32am), Community Member, 69 Posts

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

3 November 2011 at 2:57am (Last edited: 3 November 2011 4:32am), Forum Moderator, 1796 Posts

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

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

Avatar
Matty Balaam

3 November 2011 at 6:44am (Last edited: 3 November 2011 6:45am), Community Member, 69 Posts

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

3 November 2011 at 7:01am Forum Moderator, 1796 Posts

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

3 November 2011 at 7:05am Community Member, 69 Posts

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

3 November 2011 at 7:57pm Community Member, 69 Posts

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

2 December 2011 at 5:06pm Community Member, 190 Posts

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

Go to Top