RenderImage with height and width parameters

175 views
Skip to first unread message

Neil Bailey

unread,
Oct 25, 2014, 9:02:23 PM10/25/14
to glasssite...@googlegroups.com
We are using Glass Mapper w/ Page Editor for an MVC project, and I've fallen in love with how easy it is to use.  However, we have run into a limitation that I am hoping someone has resolved already.

When we use @RenderImage(Model, x=>x.SomeImageField, new {W=100,H=100}, true)

We get HTML that looks something like <img src="path/to/image?h=100&w=100" height="100" width="100" />

Normally, this would be great.  However, we have a requirement that some of our images cannot have inline height and width parameters in the HTML (its handled by CSS and JS), but we still need to be able to pass the parameters in the URL to sitecore to make sure we aren't sending some crazy big image to the browser.

Essentially, what I need is HTML that comes out like this

<img src="/path/to/image?h=100&w=100" />  <-- no inline height/width parameters

Can Glass do this for me?  Its a fairly important requirement for us.

Thanks in advance.

Neil

Neil Bailey

unread,
Oct 27, 2014, 4:18:17 PM10/27/14
to glasssite...@googlegroups.com
We managed to solve this by simply creating a class that inherits the GlassView class, and then has a method that calls the RenderImage method, and strips out the height/width parameters in the HTML tag via a regex.

This seems like a bit of a hack to me.  Perhaps in a future version, the GlassView's RenderImage will allow for specifying whether these parameters should be added to the HTML or not?
Reply all
Reply to author
Forward
0 new messages