Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glass mapper Render Image data attributes

I'm trying to render a image field with RenderImage. I need some data- attributes in the image but I can't seem to figure out how to go about implementing that. I've tried this but doesn't work

@RenderImage(image, x => x.Image, new RenderingParameters("data-protect=true"), isEditable: true)   

Thanks

like image 471
Gabbar Avatar asked Oct 20 '14 17:10

Gabbar


1 Answers

Although the answer above will work I am going to be removing ImageParameters support in the future and moving to just anonymous type support:

@RenderImage(image, x => x.Image, new { Width = 100}, isEditable: true)

The reason for this change is because having a strongly type class like ImageParameters is very limiting. Anonymous types are also a common way of doing this with other frameworks so it would fit with what everyone else is doing.

Updated to include rendering of data attributes:

@RenderImage(image, x => x.Image, new { data_protect = "true"}, isEditable: true)
like image 122
Michael Edwards Avatar answered Sep 28 '22 06:09

Michael Edwards