Jump to:

796 Posts in 409 Topics by 304 members


SilverStripe Forums » Widgets » Multiple Widget Areas. What problem?

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 1420 Views
  • tazzydemon
    Community Member
    122 Posts

    Multiple Widget Areas. What problem? Link to this post

    I have seen many people ask if you can have more than one widget area and many more reply that you can't.

    I just tried it and you can.. its as easy as this in page.php...

    static $has_one = array(
       "Sidebar1" => "WidgetArea",
    "Sidebar2" => "WidgetArea",
    "Sidebar3" => "WidgetArea"

    function getCMSFields() {
       $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar1"));
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar2"));
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar3"));

    And then just splatter the $Sidebar1 $Sidebar2 $Sidebar3 wherever you want.

    I just have to figure out how to make a pageholder page so I can start with one set of widgets for all pages.

  • Juan
    Community Member
    18 Posts

    Re: Multiple Widget Areas. What problem? Link to this post

    Hello Tazzy

    what version of silvestripe did you use on this?

    i've try it on 2.4 but it doesnt work.

  • snel
    Community Member
    10 Posts

    Re: Multiple Widget Areas. What problem? Link to this post

    I tried this in 3.1-rc1:


       private static $has_one = array(
          'MainWidgetArea' => 'WidgetArea',
          'SidebarWidgetArea' => 'WidgetArea'

       public function getCMSFields(){
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Widgets', new WidgetAreaEditor('MainWidgetArea'));
          $fields->addFieldToTab('Root.Sidebar', new WidgetAreaEditor('SidebarWidgetArea'));
          return $fields;

    and a template HomePage.ss which reads like this:

    <div class="content-container unit size3of4 lastUnit">
    <div class="content">$Content</div>

    Then, I added/removed widgets (wrote two sample widgets that return a string) in the admin-section and experienced strange behavior:

    • Log in to ss/admin
    • create page "HomePage"
    • define Widget 'weather forecast' for Widet-Area
    • publish
    • display page: weather widget is shown
    • define Widget "facebook messages" for "Sidebar"-Widget Area
    • publish
    • display page: both template blocks are shown, but only the weather-widget shows the output from the widget-Controller
    • admin: delete widget from main widget area
    • publish
    • display page: only the facebook-message widget is shown, but now includes the text, which is returned by the Widget-Controller
    • admin: exchange the facebook messages in the sidebar with the weather widget and put the facbook widget into the main widget-area
    • publish
    • display page:both template blocks are shown but this time only the facebook message widget displays the text returned by the widget-ontroler
    • admin: remove the facebook message widget
    • publish
    • display: whe facebook widget ist gone, the thext for the weather widget is shown

    From this experience, I concluded that either I misunderstood the widget/template-mechanism or the widget is broken.

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.