I want to add the same widgets to every page on my website, so adding/editing widgets on my HomePage updates every page.
I've followed the tutorial, and am SO close to getting this to work. I just need a little help on the very last stage.
In mysite/code/HomePage.php, I've added:
static $has_one = array(
"MyWidgets" => "WidgetArea",
);
and
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("MyWidgets"));
return $fields;
}
and to templatename/templates/Layout/HomePage.ss I added this:
$MyWidgets
So far so good. This works great.
However, now I need to get this data onto all other pages. $MyWidgets doesn't work on other pages without a little help, and that's where I'm getting stuck.
I've tried the following on mysite/code/Page.php, but it doesn't work.
class Page_Controller extends ContentController {
public function getMyWidgets(){
$obj = DataObject::get_one('HomePage');
return $obj->MyWidgets;
}
I would be very grateful if someone could help me with this last part, please. Thank you.