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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

control inside control


Go to End


2 Posts   669 Views

Avatar
esakrielaart

Community Member, 59 Posts

13 October 2011 at 1:10am

Hello all,

I'm struggling with the following:

I have a sidebar widget that needs to show certain items. These items, however, contain a reference ID to another table in the database with the item's content. How can I get the template to render this information, like:

Item 1
- Content 1
- Content 2
Item 2
- Content ...
.
.
.

I can (probably) only access the content through a DataObject::get() call. In the template, I suggest I need something like:

<% control getItems %>
 $Name
 <% control getContent %>
  $Name
 <% end_control %>
<% end_control %>

Any help would be highly appreceated.

Friendly regards,
Maurice

Avatar
Willr

Forum Moderator, 5523 Posts

15 October 2011 at 8:46pm

These items, however, contain a reference ID to another table in the database with the item's content.

How are these two objects related? If you're using a has_one relationship then you can simply use the ORM in the template. Also to get the items you need to use DataObject::get('ClassName') to get all the items of your ClassName.

// SomeClassName.php has something like
static $has_one = array('Content' => 'Page');

// in your widget PHP
function getItems() {
return DataObject::get("SomeClassName");
}

// in your widget template
<% control Items %>
<% control Content %>
$Title... $MenuTitle
<% end_control %>
<% end_control %>