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

nested controls


Reply


6 Posts   1294 Views

Avatar
marcink

Community Member, 89 Posts

13 April 2009 at 12:10pm

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

Avatar
marcink

Community Member, 89 Posts

13 April 2009 at 9:39pm

Edited: 13/04/2009 9:40pm

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

Avatar
Carbon Crayon

Community Member, 598 Posts

13 April 2009 at 11:36pm

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.

Avatar
marcink

Community Member, 89 Posts

14 April 2009 at 3:03am

thanks aram, i'll give it a shot.

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

Avatar
Carbon Crayon

Community Member, 598 Posts

15 April 2009 at 12:19am

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.

Avatar
marcink

Community Member, 89 Posts

15 April 2009 at 5:14am

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... :)