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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

SOLVED: Getting Filename of a resized image in view


Go to End


3 Posts   1026 Views

Avatar
Silverfish

Community Member, 59 Posts

22 November 2011 at 5:22am

Edited: 22/11/2011 5:22am

Hi All,

I'm looking for a way to geht just the path to an resized image in a template, i.e.

<div style="background:url($Img.SetWidth(100).Filename)"></div>

unfortunately when I'm writing it this way, I get

<div style="background:url(<img src="/path/to/image.jpg" alt="image" />.Filename)"></div>

Is it possible to get the filename without writing an extra method to the model?

Thanks for any hint!

Regards
SF

Avatar
rob.s

Community Member, 78 Posts

22 November 2011 at 8:03am

Edited: 22/11/2011 8:04am

Hi Silverfish,

try

<div style="background-image: url(<% control Image.SetWidth(100) %>$URL<% end_control %>)"></div>

or

<div style="background-image: url(<% control Image %><% control SetWidth(100) %>$URL<% end_control %><% end_control %>)"></div>

Avatar
Silverfish

Community Member, 59 Posts

23 November 2011 at 12:34am

Hi Rob,

The first one did the job, thanks a lot!

SF