php - How to call a widget in the template based on ID or ClassName -


i using blog module silverstripe , trying call widgets parent (blog holder) page on blog entry page. have created function runs in blogentry.php file. function gets parent page, gets widgets associated , have access 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 $widget) {             if ($widget->parentid == $widgetarea) {                 $parentwidgets->push($widget);             }         }          foreach ($parentwidgets $widget) {             error_log($widget->id);         }          return $parentwidgets;     } 

the error log within there returns 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 information how loop on in template , show widget in full? if loop , within loop enter random string of text such 'foo' display 4 times over.

<% $getparentwidgets %>     foo <% end_with %> 

i need show whole widget itself.. there way that?

thanks, if need more let me know.

the ss template equivalent $this $me. display object in current scope, provided it's capable of being rendered.

another option form arraylist associative array; can use key retrieve value within loop.

in case, i'd recommend $me. you'll want loop on results, rather changing context 'with'. 'get' prefix optional since function doesn't require arguments.

<% loop $parentwidgets %>     $me <% end_loop %> 

if ss3, should update orm retrievals.

$holder = dataobject::get_by_id('page', $this->parentid); 

is now:

$holder = page::get()->byid($this->parentid); 

and

$widgets = dataobject::get('widget'); 

is

$widgets = widget::get(); 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -