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.


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

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

Need help adding Widgets to pages other than blog

Go to End

10 Posts   4454 Views


27 August 2008 at 6:09pm (Last edited: 27 August 2008 7:36pm), Community Member, 23 Posts

Okay - I'm trying to follow the instructions here: to install widgets. I've got a Widget area in my DB, now I just need some help with the rest.

1. Do I just copy the exact code displayed on that documentation page to mysite/code/Page.php?

2. How do I know where in my template to add $Sidebar ?

I'm already frustrated with my blog that's coming up blank. I'd at least like to get this figured out.

Thanks in advance for any advice!


28 August 2008 at 10:47am Forum Moderator, 5511 Posts

1) Yes you just need to fill in the 'blanks' in your Page.php with whats listed. Your Page class should already be created in Page.php so you just need to add the "Sidebar" => "WidgetArea" bit to create a new has_one relationship (a page has one widget area) and then you need to copy the function getCMSFields() bit to add the Widget Editor to the CMS.

2) Where do you want your widgets to show?. You can add the $Sidebar in any template file, Its up to whereever you want to show your widgets. If you are using blackcandy and want the widgets in the sidebar on the left then try adding it to in themes/blackcandy/templates/Includes/ - you want to put it after the menu so put it on the second to last line - above the last </div>

3) Blank blog has come up before. Try and find your php error logs and see if theres any record of any errors to do with SilverStripe


28 August 2008 at 6:18pm Community Member, 23 Posts

Thanks so much for your help. So I got to the point where the "add widget" option is showing up in the CMS, and I was able to drag & drop my widget, but got an error message upon trying to save. Then, I logged out, did a db flush, logged back in and now I've still got the add widget tab, but can't drag and drop - in the space where before I could drop a widget, it now says "bad widget class name given". I'm pasting my code below so maybe someone might spot where I'm going wrong. I have no prior experience with PHP, so please forgive me if this turns out to be a simple fix. Nothing's simple for me right now! ack!

Code for /mysite/code/page.php :

class Page extends SiteTree {
static $db = array(
static $has_one = array(
"Sidebar" => "WidgetArea"
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar"));
return $fields;

class Page_Controller extends ContentController {
function init() {



here's the code for theme/earthling/templates/includes/ :
<% control Level(1) %>
<% if Title = Blog %>
<% else %>
<% if Title = Forums %>
<% else %>
The menu:


* <% control Children %> <% if First %> class="first"<% end_if %>> $MenuTitle
<% end_control %>

<% end_if %>
<% end_if %>
<% end_control %>


28 August 2008 at 6:32pm Forum Moderator, 5511 Posts

It all looks fine from a code point of view. You say you have the blog installed? The widget editor has a bit of a fit if there is more then 1 widget area on a page at a time so if you are running blog it could be that on the blog pages with 2 widget areas its utterly confused!.


29 August 2008 at 1:34am Community Member, 23 Posts

I do have the blog installed (still trying to figure out where to find the error log that might explain why I'm getting the blank blog page), but the pages on which I'm trying to install the widgets are just regular pages.

And does this mean that once I do get the blog up and running that I won't be able to install widgets on blog pages? Any suggestions for what I will need to do to fix that 2 widget area issue?


29 August 2008 at 9:31am Forum Moderator, 5511 Posts

for the error logs - are you developing the site locally? eg on your computer using wamp? or is it on a web server? If you are developing the site on wamp your errors are logged to C:\wamp\www\logs\php_error.log hopefully that file will have some information for you.

I dont know if 2 widgets areas are supported, they may be but Im not sure people have complained about it not working so I think what you need to do is if you define a widget area on the Page class - blog inherits from page so it will inherit the widget field from page so you just need to remove the second widget field from the blog holder by commenting out the line

Line 35 from blog/code/BlogHolder.php

// $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("SideBar"));


30 August 2008 at 5:31am Community Member, 23 Posts

Thanks so much for all your help. You've been so quick to respond. I'll give this fix a shot later today and will let you know how it goes.

really - thank you.


2 September 2008 at 4:31pm Community Member, 23 Posts


still having trouble with this. I'm trying to install a widget (the html content widget, to be exact) on the home page of a site that does NOT have the blog installed (using an external blog host for now)

I can drag & drop the widget into the right-hand column of the widgets tab, but the "Content" field doesn't show up. The widget says that if that happens, I'm supposed to save & refresh which I've done, but upon refresh, the widget is no longer in the right-hand column and I have to start all over again. But then it still doesn't work.

I'm having a helluva time with the widget installation. Doesn't seem like too many people are having my issue, so I'm going to go ahead and say it's most likely an error on my (self-taught) part.

Can anyone please advise me on how to get widgets up and running using Higherground template? I'm seriously going crazy.

The site I'm working on is and I've been working on the live server.

If there's any specific code you'd need to look at, let me know what file to post.

Go to Top