London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

DisplayTemplates for Image

Vote:
 

Using a view in the DisplayTemplates for my images. looks like this:

@model EPiServer.Url
<img src="@Model?width=@ViewData["width"]&height=@ViewData["height"]" />

Using Imageresizer and I wish to use hard typed variables for width and height instead adding it to the ViewData. This is how the view is used:

@Html.PropertyFor(p => p.CurrentPage.Image, new { @width= 50, @height=50})

Is this possible?

Second question. Is it possible to get the Image name from the Url? Using Episerver 7.5 and can't find the right way to do it. 

Thanks!

#85525
Apr 29, 2014 9:39
Vote:
 

You can create a custom display template Views / Shared / DisplayTemplates / CustomImage.cshtml

@model EPiServer.Url
<img src="@Url.ContentUrl(Model)" width="@ViewBag.width" height="@ViewBag.height"/>

    

And use it like this from your view:

@Html.DisplayFor(x => x.CurrentPage.Image, "CustomImage", new { width = 50, height = 50 })

    

But this is not strongly-typed either

#85529
Apr 29, 2014 10:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.