Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » access $Link inside a <% control .. %>

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

Page: 1
Go to End
Author Topic: 1432 Views
  • escaped
    Community Member
    6 Posts

    access $Link inside a <% control .. %> Link to this post


    i have the following controller:

    class ImagePage_Controller extends Page_Controller {
       function download() {      
          $id = Director::urlParam('ID');
          if ($id) {       
             //get a File object or subclass of (e.g. Image)
             $image = DataObject::get_by_id("Image",$id);
             $path = $image->getFullPath();
             $name = basename($path);
             $response = new HttpResponse();
             $response->addHeader("Content-disposition","attachment; filename=" . $name);
             return $response;   
          } else
             return false;

    and the following template:

    <% control Images %>
       <div class="images">
          <% control Attachment %>$CroppedImage(100,100)<% end_control %>
          <p><a href="$Attachment.GetURL" title="download">download</a></p>
          <div class="clearleft"></div>
    <% end_control %>

    Images is an DataObject, which contains an Image in field 'attachment'.

    What i am trying to do is:
    Instead of linking to the direct file, i want to call the download-Function of the controller with the id if the image. Something like:

    <p><a href="$Link(download)/$Attachment.ID" title="download">download</a></p>

    But i cannot access the '$Link' inside a control. Is there any way to achieve this?
    any ideas or solutions?



  • Pigeon
    Community Member
    243 Posts

    Re: access $Link inside a <% control .. %> Link to this post

    Hi escaped,

    To be honest, i dont completely follow what you want to do. But if you want to access a variable or method from the page you are in whilst in a control, you can use $Top.

    So $Top.Link should work for you.

  • escaped
    Community Member
    6 Posts

    Re: access $Link inside a <% control .. %> Link to this post

    thanks... That was, what i was searching for

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.