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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Automatically add widget to page type?

Go to End

2 Posts   2352 Views


Community Member, 20 Posts

1 June 2008 at 7:40pm

Hi, I'm trying to extend a page type (such as BlogEntry, GalletyPage etc.) to have a specific widget added by default (immediately after creation).
I don't want to integrate it into the *.ss-file, as it should still be possible to remove it in the CMS widget area if needed.

Any ideas where I should start looking how to realize this?



Community Member, 37 Posts

1 June 2008 at 7:51pm

Edited: 01/06/2008 7:52pm

Hi Blynx

If you have a look at blog/code/BlogHolder.php function requireDefaultRecords() you will see the code that adds the 3 widgets automatically when you install the Blog module

$widgetarea = new WidgetArea();

$blogholder->SideBarID = $widgetarea->ID;
$blogholder->publish("Stage", "Live");

$managementwidget = new BlogManagementWidget();
$managementwidget->ParentID = $widgetarea->ID;

$tagcloudwidget = new TagCloudWidget();
$tagcloudwidget->ParentID = $widgetarea->ID;

$archivewidget = new ArchiveWidget();
$archivewidget->ParentID = $widgetarea->ID;


So you should be able add widgets using this code providing you create a suitable object, in this case the object is $blogholder.
Never tried it but that's the theory...