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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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
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?
could do something like this in a function int he widget controller?
$doSiteConfig = DataObject::get_one('SiteConfig');
return $doSiteConfig->SomethingInSiteConfig;
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?
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.
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.
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.
Not sure why I didn't think of that, thank you Matty :-)