Jump to:

1374 Posts in 487 Topics by 520 members

Themes

SilverStripe Forums » Themes » lightbox: should I do this?

Discuss SilverStripe Themes.

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

Page: 1
Go to End
Author Topic: 1857 Views
  • yurigoul
    Avatar
    Community Member
    202 Posts

    lightbox: should I do this? Link to this post

    I ran accross a snippet at ssbits and I extended the snippet to to create a lightbox enabled image link in my page.ss. I have not tested this with lightbox installed but I am pretty confident this would work for lightbox and with some adaptation this should work for any other lightbox-clone:

    <% control MyImage %>
       <% control SetHeight(600) %>
          <a href="$URL" rel="lightbox">
       <% end_control %>

       <% control CroppedImage(580, 200) %>
          <img src="$URL" />
       <% end_control %>

       </a>
    <% end_control %>

    this results in:

    <a href="/s/assets/Uploads/_resampled/SetHeight600-myimage.jpg" rel="lightbox">   
       <img src="/s/assets/Uploads/_resampled/croppedimage580200-myimage2.jpg" />
    </a>

    I have three questions:

    • Is there any reason why I should not do this? I know there is also the option of adding gd functions to the page.php, so is there any reason I should be using that instead?

    • The author gave these other possiblities for controling the image: CroppedImage(w,h), PaddedImage(w,h), ResizedImage(w,h), control SetWidth(w), control SetHeight(h). These should be documented in the gd api documentation, but I can not find them. Where can I find out about these methods, and are there more?

    • I noticed I can use $Title to get the name of the image, and in this way I would be able to use the name as a title and alt attribute. However I can only use it inside the first control statement (control MyImage). Are there any other variables like that, that I can use?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: lightbox: should I do this? Link to this post

    Is there any reason why I should not do this
    No, if it works for you then roll with that.

    Where can I find out about these methods, and are there more

    Probably not a complete list but the bulk of methods are available at http://doc.silverstripe.org/doku.php?id=image

    Are there any other variables like that, that I can use?

    You can use any of the File, Image database fields or any of the methods defined in Image.php or File.php. To see whats available open up those files and see whats in the $db array.

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: lightbox: should I do this? Link to this post

    Thanks for the answer, I will certainly look into the filephp and image.php. What confused me is that I thought things like direct image manipulation should take place in the page.php and with the page.ss you just retreive the data. I could also do this with the gd functions in the page.php - is one better than the other?

    The link you gave me does not document methods like CroppedIMage. I was wondering if there was an equivalent to croppedResize etc.

    I expanded the code to this, am just sharing it. MainImage is the image and MainImageTitle is a text field that holds the title etc.

    <% if MainImage %>
       <% control MainImage %>
          <% control SetHeight(600) %>
             <a href="$URL" title="$Top.MainImageTitle" rel="lightbox">
          <% end_control %>
          <% control CroppedImage(580, 200) %>
             <img src="$URL" title="$Top.MainImageTitle" alt="$Top.MainImageTitle" />
          <% end_control %>
          </a>
       <% end_control %>
    <% end_if %>

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