Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Control in a Control

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1205 Views
  • UncleCheese
    4085 Posts

    Control in a Control Link to this post

    I have a ProductionHolder page that uses <% control Children %> to loop through all its Production objects. Each Production has a has_many with Characters. I need to loop through Characters inside of that loop. How do I do that?

    Here's what I have:

    <% control Children %>
    <% control character %>
    <% end_control %>
    <% end_control %>

    This looks like it's on the right track, but it's throwing a database error. It's filtering by the "ParentID" field, which doesn't exist, on the Character object when it should be filtering based on the ProductionID field.

    Why ParentID? What did I do wrong?

  • saimo
    Community Member
    67 Posts

    Re: Control in a Control Link to this post

    You should create new functions in the Controller class:

    function Characters() {
       return DataObject::get("Character", "ProductionID = {$this->ID}", "", "",);

    That should get the Characters. The third argument is for a SQL sort fragment eg. "Created DESC" if you need that. Replace Children with Characters in your inner control.

    This is because Children returns the pages that are children of the current page in the CMS.

    If it doesn't work then please post your Production.php file.

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.