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

SOLVED: Getting Filename of a resized image in view


Go to End


3 Posts   1356 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