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.

Widgets

Discuss SilverStripe Widgets.

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

Widget on a new Page Type


Reply

3 Posts   2037 Views

Avatar
Chajoe

21 February 2009 at 11:44am Community Member, 3 Posts

Ok, so I was able to create a new page type with this instructions posted by Willr:
----------------------------
You can have widgets on any page type by adding a WidgetArea to it. Open the page type code and add

static $has_one = array(
"MyWidgets" => "WidgetArea"
);

then in the getCMSFields you will need to add the widget drag and drop system

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("MyWidgets"));
return $fields;
}

Then last but not least you need to open up your template file and add the code to render the widget area. In this example you would need to put $MyWidgets in the template some where.

Remember to db/build and then flush the page.
----------

I created a new HomePage.php, flushed the database and it loaded on the CMS... and it has the widget tab!
:) !
it took me a while to figure this out...
My problem now is that the pages I create with that page type print out the following:

Error
The website server has not been able to respond to your request.

I've been tryint to put the "$MyWidgets" to call the function on the page.ss of my template, also creating a new "HomePage.ss" but no luck...
Please Help

thx

Avatar
Nivanka

27 March 2009 at 2:50pm Community Member, 395 Posts

Okay, now seems like you have done everything good, but did you run a http://mysite.com/db/build?flush=1

if not try with that.

Avatar
gkinane

14 June 2009 at 3:20am Community Member, 22 Posts

Hi , I've tried your method to add widget type but no success. The following is the code I've added to page.php.
   public static $db = array(
   );
   
public static $has_one = array(
   );
   static $has_one = array(
"MyWidgets" => "WidgetArea"
);
   
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("MyWidgets"));
return $fields;
}

When I save the file to server I then cannot login or run db/build. I also added the field to page.ss just before the last /div.

I am a complete newbie to PHP and SS so I probably have screwed up the code somewhere. Any help appreciated.

GK