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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Using $SetSize in Templates


Go to End


3 Posts   1742 Views

Avatar
bcgreen24

Community Member, 2 Posts

6 September 2015 at 2:40pm

Edited: 06/09/2015 2:42pm

Hi, all! So I'm brand-spankin' new to SilverStripe, and while I've had success in modifying the 'Gallery' module to include an option to set the thumbnail size, I'm having issues using the thumbnail width/height values in my template. The code below does not show any of the gallery images (if I hardcode a width and height, such as 250,250 they display)-- but after the loop where I display the $ThumbWidth and $ThumbHeight values, those are displaying just fine...so I know those values are available to the template.

<% loop OrderedImages %>
        <a class="fancybox" data-fancybox-group="gallery" href="$Filename" title="$Caption">
                $SetSize($ThumbWidth, $ThumbHeight)
        </a>
<% end_loop %>
Width: $ThumbWidth&nbsp;
Height: $ThumbHeight

So apparently, the $SetSize function is not liking the values I'm passing to it. Can someone shed some light on where my mistake is?

Thanks!
Bryan

Avatar
MichalKleiner

Community Member, 4 Posts

6 September 2015 at 5:20pm

Those variables are not set on the OrderedImage item which is the context of the loop. Use $Top.ThumbWidth and $Top.ThumbHeight as parameters.

Avatar
Feejin

Community Member, 4 Posts

1 October 2015 at 11:26pm

In case you're not aware of it, you can also use CroppedImage to crop and resize (as opposed to resize then pad with whitespace).

{$Top.CroppedImage($ThumbWidth, $ThumbHeight)}

And if you find it crops bits out that you don't want to be cropped out, there's always the Focus Point module.