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.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

$Top.Function(param) possible in a control loop

Go to End

4 Posts   1833 Views


Community Member, 5 Posts

9 December 2010 at 10:02am

Edited: 09/12/2010 10:28am


is the following possible in a template using $Top and control loops?

I have two functions in my controler (extends Page_Controler).

getAlbumImages() ... returns a DataObject with all images contained in folder: assets/images/
getAlbumTitle($imageFile) ... should return a image description from the image filename 
(XX_image_description_in_file.ext ==> image description in file)

In my template I use something like:

<% if getAlbumImages %>
    <% control getAlbumImages %>
       <a href="$URL" rel="album" title="$Title">$SetRatioSize(150,150)</a>
    <% end_control %>
<% end_if %>

Is there any chance to use something like this instead:

<a href="$URL" rel="album" title="$Top.getAlbumTitle($Title)">$SetRatioSize(150,150)</a>

So far everything works fine, I just would like to have the image title (XX_my_image_title.jpg more clean ==> my image title).

If the template thingy doesn´t work, what else could I do?



Community Member, 5 Posts

9 December 2010 at 10:33am

Edited: 09/12/2010 10:39am


thanks to Arams great blog, I found the answer to my problem:
Just added a Decorator for the Image Class (as shown in Arams blog), which allows me to use this in my template:

<a href="$URL" rel="album" title="$getImageDescription">$SetRatioSize(150,150)</a>

Amazing, about 20 lines of code for a simple gallery, which creates thumbnails from all images located in a specified assets folder including a nice jQuery Colorbox animation for the full image size.



Forum Moderator, 5523 Posts

9 December 2010 at 4:33pm

Also FYI to anyone wondering


Won't work. You cannot as of 2.4 pass variables (ie $Foo) into the method or function. It has to be a static value e.g '2'.


Community Member, 5 Posts

9 December 2010 at 7:04pm

Hi Willr,

already expected something like this, as I haven't found any code around which uses this "technique" :-)
So thanks for your answer, highly appreciated.