November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
You can define your property like this:
[UIHint(UIHint.Image)]
public virtual Url Image { get; set; }
And use the following code in your DisplayTemplate:
@model EPiServer.Url
@if (Model != null)
{
<img src="@Url.ContentUrl(Model)" alt="" />
}
Hope this helps
Now i've tried to move my Image.cshtml file to /Views/Shared folder but still just the link.
In my Views folder i have created a new folder called DisplayTemplates and in this folder a Image.cshtml file that looks like this:
Are you sure? Seems to me that you did not put it in the "shared" folder, but maybe I misunderstood.
I've come across something similar and it looked to me as if image renderers are only used for rendering MediaTypes (ie images) when they are used in Content Areas. Using the EPiServer PropertyFor helper / EPiServer Property control with an Image property didn't use the custom rendering tempate. I'm not sure whether this is a bug or by design.
Try dropping your image in a content area and see what happens.
It was me that was unclear when writing, my DisplayTemplates folder was under the Shared folder.
By that I mean - add a content area property to your NewsBlock and add the content area to the NewsBlock View. Then using the edit UI add the Image to the content area in your NewsBlock by dragging and dropping
Per Magne - Not on the NewsBlockViewModel.
My NewsBlock.cs looks like this:
[UIHint(UIHint.Image)]
public virtual Url Image { get; set; }
My NewsBlockViewModel looks like this:
public string Heading { get; set; }
public string MainIntro { get; set; }
public ContentReference NewsRoot { get; set; }
public IEnumerable<PageData> NewsPages { get; set; }
public Url Image { get; set; }
public NewsBlockViewModel(string heading, string intro, ContentReference contentReference, Url image)
{
Heading = heading;
MainIntro = GetSubString(intro);
NewsRoot = contentReference;
NewsPages = GetNewsPages();
Image = image;
}
You should add it to the view model as well. Otherwise it will not know which display template to load, and will load the default one, which just displays the url in this case
Great, adding the UiHint to the viewmodel did the trick! Thanks to all of you for helping me!
Dear friends,
I've been trying to implement a display template for images and then use this template in a block. The problem is that no images is rendered, just the url to the image.
I've created a newsblock with a image property like this:
[UIHint(UIHint.Image)]
public virtual ContentReference Image { get; set; }
My NewsblockController looks like this:
public class NewsBlockController : ActionControllerBase, IRenderTemplate<NewsBlock>
{
public ActionResult Index(NewsBlock currentBlock)
{
var model = new NewsBlockViewModel(currentBlock.Heading, currentBlock.MainIntro, currentBlock.NewsRoot, currentBlock.Image);
return PartialView(model);
}
}
And my NewsblockView looks like this:
@model HiQAllehanda.Models.ViewModels.NewsBlockViewModel
<div class="newsblock">
<h1>@Html.PropertyFor(x => x.Heading)</h1>
@Html.PropertyFor(m => m.Image
</div>
In my Views folder i have created a new folder called DisplayTemplates and in this folder a Image.cshtml file that looks like this:
@model EPiServer.Core.ContentReference
@if(Model != null)
{
<img src="@Url.ContentUrl(Model)" alt="" />
}