Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:59:54+00:00 2026-06-11T19:59:54+00:00

Is it possible to set default widgets for new pages within silverstripe or have

  • 0

Is it possible to set default widgets for new pages within silverstripe or have child pages initially inherit their widgets from their parent? The whole side bar is taken up by custom widgets in a site I am working on and it would be nice for a select few to appear by default on the (many) new pages the client will be creating. They should still have the option to remove them or add any of the others.

I have searched the docs and not found any indicators that this is possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:59:55+00:00Added an answer on June 11, 2026 at 7:59 pm

    default widgets should be rather easy to do
    We can add a Widget Area to the SiteConfig where you can set the defaults, and then use populateDefaults in Page to copy the widgets from SiteConfig to the new Page:

    File mysite/code/mysiteSiteConfigDecorator.php

    class mysiteSiteConfigDecorator extends DataObjectDecorator {
        public function extraStatics() {
            return array(
                'has_one' =>array(
                    'DefaultWidgets' => 'WidgetArea'
                ),
            );
        }
        public function updateCMSFields(FieldSet &$fields) {
            $fields->removeByName('Theme');
            $fields->addFieldToTab('Root', new Tab('DefaultWidgetsTab', _t('SiteConfig.DefaultWidgetsTab', 'Default Widgets for new Pages')));
            $fields->addFieldToTab("Root.DefaultWidgetsTab", new WidgetAreaEditor("DefaultWidgets"));
        }
    }
    

    File mysite/_config.php

    ...
    
    Object::add_extension('SiteConfig', 'mysiteSiteConfigDecorator');
    
    ...
    

    File mysite/code/Page.php

    class Page extends SiteTree {
        public static $has_one = array(
            'Sidebar' => 'WidgetArea'
        );
        public function populateDefaults() {
            parent::populateDefaults();
            if ($this->Sidebar()) {
                $widgetArea = new WidgetArea();
                $widgetArea->write();
                $this->SidebarID = $widgetArea->ID;
            } else {
                $widgetArea = $this->Sidebar();
            }
            $siteConfig = SiteConfig::current_site_config();
            if ($siteConfig && $siteConfig->DefaultWidgets() && $siteConfig->DefaultWidgets()->Widgets()->exists()) {
                foreach ($siteConfig->DefaultWidgets()->Widgets() as $widget) {
                    $widget->ID = 0;
                    $widget->write();
                    $widgetArea->Widgets()->add($widget);
                }
            }
        }
        public function getCMSFields() {
            $fields = parent::getCMSFields();
            $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar"));
            return $fields;
        }
    }
    
    ...
    

    However, coping from the parent isn’t that easy.
    But if you want you could also just check if the current Page has widgets, if not, display the parent widgets, like so:

    class Page extends SiteTree {
        ...
        public function SidebarForTemplate() {
            if ($this->Sidebar())
                return $this->Sidebar();
            elseif ($this->Parent())
                return $this->Parent()->SidebarForTemplate();
            return false;
        }
        ...
    }
    

    and then use $SidebarForTemplate in templates

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set a default selection on an NSPopupButton? I have one
Hi there is possible to set a default language or set a new one
I'm curious if it's possible to set my default Ruby interpreter within my $HOME/.rvmrc
Is it possible to write similar construction? I want to set, somehow, default value
Is it possible to set a default value for a variable argument list in
Is it possible to set a default behaviour for custom (non-native) methods/functions in Java?
Is it possible to set a default value without the body of a property?
A friend asked if it is possible to set the default place where users
Is it possible to set default log level for entire applicaton? I would like
Is it possible to set default headers for boto requests? Basically I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.