Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » Image as link

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

Page: 1
Go to End
Author Topic: 1050 Views
  • Iussu
    Avatar
    Community Member
    2 Posts

    Image as link Link to this post

    I have a uploadable image that apears on the page. I want to make it a clickable link so i went about and tried

    $NewProduct.SetHeight(150).URL

    to get the path of the image resized.

    But that makes the image not show up at all. Am I missing something very easy?

    Thanks in advanced.

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Image as link Link to this post

    Try:

    <a href="$NewProduct.URL">$NewProduct.SetHeight(150)</a>

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Image as link Link to this post

    Hi Iussu,

    Do you want to link to the full-sized original or a resized derivative?

    Ben

  • Iussu
    Avatar
    Community Member
    2 Posts

    Re: Image as link Link to this post

    Sorry for getting back late, howard thanks, that solved one part of my new probelms.

    Ben, my main issue is that I am trying to get Lightbox to work. I am new to this and I cannot find anything that tells me how to code it so i can easily just grab the URL to make it work with Lightbox. Any info on where i can look to get info would help.

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Image as link Link to this post

    Hello,

    Due to irregularities in how the current template parser works, $NewProduct.SetHeight(150).URL is invalid syntax. To achieve the desired effect, you could define a method in your page's class that returns the URL you want (something like " return $this->NewProduct->SetHeight(150)->URL").

    Ben

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Image as link Link to this post

    Do you try:

    <% control NewProduct.SetHeight(150) %>
       <a href="$URL">$Tag</a>
    <% end_control %>

  • teejay
    Avatar
    Community Member
    63 Posts

    Re: Image as link Link to this post

    How would u do it for this case ??

    <% control Images %>

       <a href="$ImageResource.URL" rel="shadowbox[$StallionID]">
          <% control ImageResource %>
             <% control CroppedImage(150, 115) %>
             <img src="$URL" title="$Top.Title" alt="$Top.Title" />
             <% end_control %>
          <% end_control %>
       </a>

    <% end_control %>

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