4
Html.Glass().RenderImage(Model, x => x.Logo, new { mw = 200 }, Editable:true) 

The code above outputs an img tag with the full URL including the hashed parameters.

I want a way to get just the URL (without writing a lot of extra code). The purpose of this is to set an inline background image style.

I know the Glass Mapper Image class has a Src property but that just provides the basic URL without the hashed parameters, so the image would be downloaded full size.

6

This will work for the basic params;

@using Sitecore.Resources.Media

<div style="background-image:url(@HashingUtils.ProtectAssetUrl(string.Format("{0}?{1}", Model.Logo.Src, new MediaUrlOptions { MaxWidth = 200 })))">Hello</div>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.