How to output a Richtext field in Feather list view
Currently I ran into a strange bug, images in rich text field are broken in feather list(master) view.
I have a custom module and a simple content type that contains a short text field "Title" and a rich text field "Content". And I created a custom list view that shows both Title and Content. Here is the code:
@model Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Models.DynamicContentListViewModel
@using Telerik.Sitefinity.Frontend.Mvc.Helpers;
@foreach (var item in Model.Items)
<
div
class
=
"@Model.CssClass"
>
<
h2
class
=
"title"
>@item.Fields.Title</
h2
>
<
div
class
=
"content"
>
@Html.Raw(item.Fields.Content)
</
div
>
</
div
>
When I opened the page in chrome, the images I put in rich text are all broken, this is what I saw in the developer tool:
<
img
src
=
"[images|OpenAccessDataProvider|tmb:thumb36]12341234-1234-1234-1234-1234123412341234"
data-displaymode
=
"Thumbnail"
alt
=
"Test Image"
title
=
"test_image"
>
It seems the image in rich text was not "translated" at all. Is there anything special I need to do if I want to output rich text in the list view?
Hi Ethan, you can resolve links like that:
@using Telerik.Sitefinity.Web.Utilities;
@using Telerik.Sitefinity.Modules.GenericContent;
...............
@Html.Raw(LinkParser.ResolveLinks(item.Fields.Title, DynamicLinksParser.GetContentUrl, null, false))
...............
Thanks Vicor, this helps a lot. Your code doesn't work instantly though because item.Fields.Content is dynamic. I got it to work by making a small modification:
@using Telerik.Sitefinity.Frontend.Mvc.Helpers;
@using Telerik.Sitefinity.Web.Utilities;
@using Telerik.Sitefinity.Modules.GenericContent;
@using Telerik.Sitefinity.Model;
@Html.Raw(LinkParser.ResolveLinks(item.Fields.Content as Lstring, DynamicLinksParser.GetContentUrl, null, false))
Thank you very much!