How To Render Custom HTML For Episerver Properties
Wed 13 July, 2016 / By Jon D Jones
In today's post, I'm going to talk a little about how Episerver works and how we can take advantage of that fact to render custom HTML for Episerver properties like content areas, images or XhtmlString.
Creating Custom Image HTMLTo run through a quick example, if we look in the 'Image.ascx' files, you will see this HTML
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EPiServer.Core.ContentReference>" %> <%@ Import Namespace="EPiServer.Web.Mvc.Html" %> <img src="<%: Url.ContentUrl(Model) %>" alt="" />Now, say every time we wanted to render an image you want to add a watermark to it, you could completely delete the img tag and instead use a custom HTML helper method that stamps the watermark on it. If you have read my article How To Implement a Donut Hole Cache In Episerver, you can learn how to create a custom HTML helper for a content area (same principles apply). For a silly example, if you changed Image.ascx to this
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EPiServer.Core.ContentReference>" %> <%@ Import Namespace="EPiServer.Web.Mvc.Html" %> IMAGE GOES HEREInstead of rendering images on your website, you will see the text called 'IMAGE GOES HERE'.