Nil Pun
Nil Pun

Reputation: 17383

Sitecore Glass Mapper - GlassHtml.RenderImage

I noticed the tutorial below using GlassHtml.RenderImage where we can specify the width and height of an image.

http://glass.lu/docs/tutorial/sitecore/tutorial16/tutorial16.html

<%= GlassHtml.RenderImage(Model, x => x.FeaturedImage) %>

I tried to use this function using @Glass.Mapper.Sc.GlassHtml.RenderImage but this SC.GlassHTML doesn't seem to have RenderImage

Can someone please help, what am I missing?

Thanks.

Upvotes: 0

Views: 2460

Answers (1)

Ruud van Falier
Ruud van Falier

Reputation: 8877

I tried to use this function using @Glass.Mapper.Sc.GlassHtml.RenderImage but this SC.GlassHTML doesn't seem to have RenderImage

It doesn't work that way; you're trying to access an instance method as if it were static.
Your views need to inherit from Glass.Mapper.Sc.Web.Mvc.GlassView<T> so it exposes the GlassHtml methods on your views.

Configure your /Views/web.config like this:

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="Glass.Mapper.Sc.Web.Mvc.GlassView">
    <!-- snipped other lines... -->

After that you can access the GlassView methods (which call GlassHtml methods) in your views like this:

@RenderImage(x => x.FieldName, new ImageParameters { Width = 80, Height = 80})

Upvotes: 4

Related Questions