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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

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

Widget on a new Page Type


Go to End


3 Posts   3059 Views

Avatar
Chajoe

Community Member, 3 Posts

21 February 2009 at 11:44am

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

Community Member, 400 Posts

27 March 2009 at 2:50pm

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

Community Member, 22 Posts

14 June 2009 at 3:20am

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