Jump to:

791 Posts in 369 Topics by 303 members

Widgets

SilverStripe Forums » Widgets » [Solved] Override WidgetHolder.ss

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 2763 Views
  • FungshuiElephant
    Avatar
    Community Member
    57 Posts

    [Solved] Override WidgetHolder.ss Link to this post

    I have a widget on a page.
    It's wrapped in HTML by the silverstripe/sappire/templates/WidgetHolder.ss file which contains:

    <div class="WidgetHolder">
    <h3>$Title</h3>
    $Content
    </div>

    I would prefer the title to be an h2 element rather than an h3 element.

    I copied the above, changing h3 to h2 and put it in silverstripe/themes/mytheme/templates/Includes as per this page http://doc.silverstripe.org/doku.php?id=widgets

    You can override the WidgetHolder.ss and Widget.ss templates in your theme too by adding WidgetHolder and Widget templates to themes/myThemeName/templates/Includes/

    but it didn't work.
    If I delete the core sapphire file (silverstripe/sappire/templates/WidgetHolder.ss) it works fine but obviously I don't want to do that because it will break following an update to the core sapphire files.
    Any ideas?

  • FungshuiElephant
    Avatar
    Community Member
    57 Posts

    Re: [Solved] Override WidgetHolder.ss Link to this post

    It seems that I should have put the modified WidgetHolder.ss into silverstripe/themes/mytheme/templates not silverstripe/themes/mytheme/templates/Includes. I moved the file and it worked.
    This makes more sense as I'm not including it.
    I think that the documentation (http://doc.silverstripe.org/doku.php?id=widgets) is incorrect.

  • christophermanning
    Avatar
    Community Member
    3 Posts

    Re: [Solved] Override WidgetHolder.ss Link to this post

    I just ran into the same problem. Your solution worked correctly and it seems as either the documentation is misleading or incorrect.

  • Tó Morais
    Avatar
    Community Member
    1 Post

    Re: [Solved] Override WidgetHolder.ss Link to this post

    Hello!
    My problem was that i didn't want to have my html code inside the widgetHolder div so i change the template used.
    If you just want to change the template used by your widget you can override the widget Holder by overriding your controller:

    ...

    class YOURWIDGET_Controller extends Widget_Controller {
    function WidgetHolder() {
    return $this->renderWith("YOURTEMPLATE");
    }

    ...
    }

    And your model

    class YOURWIDGET extends Widget {
    ...
    function WidgetHolder() {
    return $this->renderWith("YOURTEMPLATE");
    }
    ...
    }

    That would do the trick. And this way you keep the other widgets that used the default widgetHolder unchanged.

  • stevanovich
    Avatar
    Community Member
    59 Posts

    Re: [Solved] Override WidgetHolder.ss Link to this post

    Just as a matter of interest as I tried to change my WidgetHolder.ss I was frustrated to the limit for it not changing then I realised that one has been put in the latest Silverstripe in the blackcandy_blog/templates/ so look there to change.

  • priithansen
    Avatar
    Community Member
    25 Posts

    Re: [Solved] Override WidgetHolder.ss Link to this post

    One way to wrap each widget in the area with extra code.

    <% control SideBar %>
       <% control Widgets %>
          <div class="extrahtml">
             $Content
          </div>
       <% end_control %>
    <% end_control %>

    2763 Views
Page: 1
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.