Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
DisplayTemplate for Imagefiles in EPiServer. UiHint.Image on ContentReference.
@using EPiServer.Core
@using EPiServer.Editor
@using EPiServer.ServiceLocation
@using EPiServer.Web.Routing
@model ContentReference
@{
var link = "";
var cssClass = ViewData["cssClass"] ?? "";
if (!ContentReference.IsNullOrEmpty(Model))
{
var currentContent = ServiceLocator.Current.GetInstance<EPiServer.IContentLoader>().Get<MediaData>(Model);
link = UrlResolver.Current.GetUrl(currentContent.ContentLink);
}
var svgLink = "";
var svgRef = ViewData["svgModel"] as ContentReference;
if (!ContentReference.IsNullOrEmpty(svgRef))
{
if (svgRef != null)
{
var svgContent = ServiceLocator.Current.GetInstance<EPiServer.IContentLoader>().Get<MediaData>(svgRef);
svgLink = UrlResolver.Current.GetUrl(svgContent.ContentLink);
}
}
bool inEditMode = PageEditing.PageIsInEditMode;
}
@if (!string.IsNullOrEmpty(svgLink) && !inEditMode)
{
<img src="@svgLink" alt="" class="@cssClass" data-fallback="@link" svg />
}
else
{
<img src="@link" alt="" class="@cssClass" />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment