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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   737 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 %>