Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

two widgetareas for a page


Reply

2 Posts   972 Views

Avatar
Nivanka

15 February 2009 at 6:24pm Community Member, 395 Posts

I need to have two sidebars, and two widgetareas for them.

but when I add the two WidgetAreaEditors, the second WidgetAreaEditor doesn't work. I just try to check what has happened and I found that both the WidgetAreaEditors use the same ID WidgetAreaEditor_availableWidgets.

has anyone got a solution for this?

Avatar
Dramew

18 February 2010 at 8:03pm Community Member, 9 Posts

Maybe it will be useful for someone.
The only way to have two sidebars I found at the moment is:

  • Create 2 new classes like:

    class SidebarOne extends Page {
       static $db = array();
       static $has_one= array(
          "SideBar" => "WidgetArea",
       );
    class SidebarTwo extends Page {
       static $db = array();
       static $has_one= array(
          "SideBar" => "WidgetArea",
       );


  • Then you can get them with (put this in Page_Controller):

    /*** Get Widgets to show 'em on a page*/
    public function GetSidebarOne(){
    return DataObject::get_one("SidebarOne");
    }
    public function GetSidebarTwo(){
    return DataObject::get_one("SidebarTwo");
    }


  • In templates use smth like:

    <% if GetSidebarOne %>
       <% control GetSidebarOne %>
          $SideBar
       <% end_control %>
    <% end_if %>


Not sure if it is the best way, but nevertheless.