Jump to:

796 Posts in 409 Topics by 304 members


SilverStripe Forums » Widgets » A single widget area instance shared across whole site (not 1 widget area instance per page)...

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 510 Views
  • vwd
    Community Member
    158 Posts

    A single widget area instance shared across whole site (not 1 widget area instance per page)... Link to this post


    The site we're building at the moment will have an identical widget area instance across all pages of the site. Previously, we had the widget area added to the Page class, but obviously this meant that each Page object/child will have its own instance of a widget area.

    So if we were to have the same widgets across all the pages, we would have to manually add them to each page via the Widget editor tab.

    To have a site-wide widget area instance, we've decorated SiteConfig with the widget area. Now we get a widget area under SiteConfig, and whatever widgets we add here should be shared across the site.


    class CustomSiteConfig extends DataObjectDecorator {
    function extraStatics() {
    return array(
    'has_one' => array(
    'SiteWideWidgetArea' => 'WidgetArea'

    public function updateCMSFields(FieldSet $fields) {
    $fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("SiteWideWidgetArea"));

    Template: eg Page.ss


    Is there anything wrong with this approach?

    And also, in the past, some have commented that they've had difficulty to have 1 Widget area per page... But it hasn't been a problem getting more than 1 widget area... Are we doing the right thing here? Seems legit...


    class Page extends SiteTree {

       public static $has_one = array(
    "BottomWidgetArea" => "WidgetArea",
    "Bottom2WidgetArea" => "WidgetArea"

    public function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("PageWidgetArea"));
    $fields->addFieldToTab("Root.Content.Widgets2", new WidgetAreaEditor("AnotherPageWidgetArea"));

    return $fields;

    Template: page.ss


    Thanks for your input...


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.