Jump to:

22977 Posts in 11742 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » control inside control

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

Page: 1
Go to End
Author Topic: 285 Views
  • esakrielaart
    Avatar
    Community Member
    53 Posts

    control inside control Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: control inside control Link to this post

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

    285 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.