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.

General Questions /

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

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

control inside control


Reply


2 Posts   421 Views

Avatar
esakrielaart

Community Member, 56 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, 5513 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 %>