5

We're using GlassMapper 4.0.5.54 in Sitecore 8.1 Update 1 MVC. The problem is, when rendering an ImageField, the height and width attributes are written in the img-tag - but only in Page Editor mode.

We tried different approaches like

@Html.Glass().RenderImage(Model, x=> x.ImageField, outputHeightWidth:false, isEditable:true, parameters:new {mw = 1218, mh = 530})

@Html.Glass().Editable(x => x.ImageField, new { mw = 1218, mh = 530, width = (string)null, height = (string)null })

But we always get

<img src="http://url_to_local_website/-/media/image_1218x530.jpg?h=530&amp;la=en&amp;mh=530&amp;mw=1218&amp;w=1216&amp;hash=452505F9D5896956CB6B0F284755555217E62D8A" alt="Alt Text" width="1216" height="530" sc-part-of="field" class="scEnabledChrome">

So even when using the explicit parameter outputHeightWidth:false it outputs width and height attributes in Page Editor and distorts the image. Any suggestions? Or is it a bug?

In a comment on Glass Mapper ImageParameters someone else mentions the same behavior. But there is no answer to it.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
z00mable
  • 304
  • 2
  • 11
  • In Page Editor mode, Glass uses the standard Sitecore pipelines to render the markup. Setting these attributes in Glass therefore have no effect. – jammykam Jan 20 '16 at 11:57
  • So I have to hook into the Sitecore pipeline where it renders the markup and remove these attributes? Like for example here [http://www.mikkelhm.dk/archive/removing-width-and-height-tags-from-fieldrenderer-and-scimage/](http://www.mikkelhm.dk/archive/removing-width-and-height-tags-from-fieldrenderer-and-scimage/) – z00mable Jan 20 '16 at 12:17
  • That would be one way to do it, an alternative is to remove the height/width info on the media item itself (but that might not be desirable) – jammykam Jan 20 '16 at 18:55

0 Answers0