Jump to:

794 Posts in 408 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » $SiteConfig.XX in Widget template?

Discuss SilverStripe Widgets.

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

Page: 1 2
Go to End
Author Topic: 1912 Views
  • socks
    Avatar
    Community Member
    190 Posts

    $SiteConfig.XX in Widget template? Link to this post

    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

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: $SiteConfig.XX in Widget template? Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: $SiteConfig.XX in Widget template? Link to this post

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

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

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: $SiteConfig.XX in Widget template? Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: $SiteConfig.XX in Widget template? Link to this post

    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.

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: $SiteConfig.XX in Widget template? Link to this post

    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.

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: $SiteConfig.XX in Widget template? Link to this post

    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.

  • socks
    Avatar
    Community Member
    190 Posts

    Re: $SiteConfig.XX in Widget template? Link to this post

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

    1912 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.