Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » $Top.Function(param) possible in a control loop

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

Page: 1
Go to End
Author Topic: 1292 Views
  • abyss
    Avatar
    Community Member
    5 Posts

    $Top.Function(param) possible in a control loop Link to this post

    Hi,

    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?

    Cheers

  • abyss
    Avatar
    Community Member
    5 Posts

    Re: $Top.Function(param) possible in a control loop Link to this post

    Hi,

    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.

    Cheers

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: $Top.Function(param) possible in a control loop Link to this post

    Also FYI to anyone wondering

    $Top.getAlbumTitle($Title)

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

  • abyss
    Avatar
    Community Member
    5 Posts

    Re: $Top.Function(param) possible in a control loop Link to this post

    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.

    Cheers

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