Finally got a chance to use Silverstripe and I’m on top of most things I need but was wondering if I could get some advice on a particular problem I’m having. Google/the forums haven’t been too helpful.
My Basic question is how can I access properties from one step higher in a nested control (in a .ss template). eg:
<% control one %> <% control two %> $Parent.MyProperty <% end_control %> <% end_control %>
I would have thought that calling $Parent from within control two would refer to control one and I could access the property from there, but it doesn't seem to work.
My specific set up is that I have a parent page, that is using the AllChildren control to display content from all of it child pages. Within each page I am using a control to build an image gallery for which I need to pass a shared unique id to all of it’s images.
The code is structured like this:
<% control AllChildren %> <table class="gallery_thumbs" cellpadding="0" cellspacing="0"> <tr> <% control GalleryImages %> <td><a class="gallery_item_link" href="$Image.URL" rel="gallery_$Parent.Pos" title="$Caption"><div>$Image.CroppedImage(80,55)</div></a></td> <% end_control %> </tr> </table> <% end_control %>
So on each of the sub pages there is a GalleryImage control which stores the photos for it’s gallery. The lightbox I am using groups images on the page via shared rel tag so I need images from each gallery to have the same rel tag (which is different to the rel tag used for the other galleries), hence I am trying to use the $Pos value for the sub page it’s on, however it doesn’t seem to work,it returns “1” for every page gallery.
I’m not sure if Silverstripe is supposed to be able to do that – I’m suspicious that from what I could tell on the forums the $Parent command is for traversing up the site tree as opposed to nested controls, but I’m eagerly hoping there is a way to do what I’m trying to.
Would be grateful for any advice at all, cheers,