753 Posts in 310 Topics by 289 members
| Go to End | Next > | |
| Author | Topic: | 1357 Views |
-
$SiteConfig.XX in Widget template?

9 March 2011 at 5:07pm Last edited: 3 November 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
-
Re: $SiteConfig.XX in Widget template?

3 November 2011 at 1:28am Last edited: 3 November 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?
-
Re: $SiteConfig.XX in Widget template?

3 November 2011 at 2:57am Last edited: 3 November 2011 4:32am
could do something like this in a function int he widget controller?
$doSiteConfig = DataObject::get_one('SiteConfig');
return $doSiteConfig->SomethingInSiteConfig; -
Re: $SiteConfig.XX in Widget template?

3 November 2011 at 6:44am Last edited: 3 November 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?
-
Re: $SiteConfig.XX in Widget template?

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.
-
Re: $SiteConfig.XX in Widget template?

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.
-
Re: $SiteConfig.XX in Widget template?

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.
-
Re: $SiteConfig.XX in Widget template?

2 December 2011 at 5:06pm
Not sure why I didn't think of that, thank you Matty
| 1357 Views | ||
| Go to Top | Next > |



