I am using the blog module with SilverStripe and I am trying to call all widgets from the parent (blog holder) page on the blog entry page. I have created a function which runs in the BlogEntry.php file. This function gets the parent page, gets the widgets associated with it and I now have access to the widget information.
function getParentWidgets() {
$Holder = DataObject::get_by_id('Page', $this->ParentID);
if (isset($Holder->MyWidgetAreaID)) {
$WidgetArea = $Holder->MyWidgetAreaID;
}
$Widgets = DataObject::get('Widget');
$parentWidgets = new ArrayList();
foreach ($Widgets as $Widget) {
if ($Widget->ParentID == $WidgetArea) {
$parentWidgets->push($Widget);
}
}
foreach ($parentWidgets as $widget) {
error_log($widget->ID);
}
return $parentWidgets;
}
The error log within there returns the following
[Tue Jul 07 13:51:01 2015] [error] [client 10.0.2.2] 4
[Tue Jul 07 13:51:01 2015] [error] [client 10.0.2.2] 5
[Tue Jul 07 13:51:01 2015] [error] [client 10.0.2.2] 6
[Tue Jul 07 13:51:01 2015] [error] [client 10.0.2.2] 7
I have access to this information but how would I loop over this in the template and show the widget in full? Currently if i loop and within the loop i enter a random string of text such as 'foo' it will display that four times over.
<% with $getParentWidgets %>
foo
<% end_with %>
I just need to show the whole widget itself.. is there a way to do that?
Thanks, if you need anything more let me know.