Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » nested controls

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: 1233 Views
  • marcink
    Avatar
    Community Member
    89 Posts

    nested controls Link to this post

    hi,

    i have two nested controls:
    <% control Images %>
    ....
    <% control Top.Names %>
    ....
    <% end_control %>
    <% end_control %>

    inside the second control i need to check an property from the first one inside an if block.
    <% control Top.Names %>
    <% if ImagesID == NamesID %>
    ....
    <% end_if %>
    <% end_control %>

    is this possible? if not, i can call a function on the controller, but here as well i would have to pass the value from ImagesID to the method.
    <% control Images %>
    ....
    <% control Top.getNames(ImagesID) %> // how to call the method with the correct parameter??
    ....
    <% end_control %>
    <% end_control %>

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: nested controls Link to this post

    this is driving me nuts...

    still the same setting:
    <% control Images %> // there are two images at the moment
    ....
    <% control Top.getNames %> // so this control should run 2 times, each time with a different DataObjectSet
    ....
    <% end_control %>
    <% end_control %>

    getNames is a method on the controller.
    the method returns a DataObjectSet. when i comment out the return, and print_r(); the dataset i get with:
    DataObject::get(); i get the correct sets.

    but when i try to return the sets to my template, i get both times the first set.

    any help??

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: nested controls Link to this post

    Hi marcink

    The issue you ahve here is that your using Top.getNames so the getNames function is being run from the current pages context each time, not the context of the Image.

    Your best bet is to subclass Image and add the method to the model so that you can then run it from within the Images Control loop.

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: nested controls Link to this post

    thanks aram, i'll give it a shot.

    what you think, is it not possible to get a property from the parent control block?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: nested controls Link to this post

    As far as I know it's not possible, you can only get the current control block or the top level control, there is no way to 'step up', although that would be a great feature to have.

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: nested controls Link to this post

    thanks. i got it working.

    i didn't had to extend Image, cause the image was inside a DataObject. so i had to write a method on that dataobject, witch could return the infos i needed. thanks for pointing it out...

    1233 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.