How to render RTE content to a JSON object in macro?
I have created a few macros now that create json objects with their data (I use JS to render that data to the page). Those have been lists of things using simple text fields. But now I have to retrieve data from a RTE field - and I'm experiencing problems doing that.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using System.Globalization
<script>
@{
var latestArticlesNodeID = Model.MacroParameters["ArticlesFolder"];
var latestArticlesNode = Umbraco.Content(latestArticlesNodeID);
var latestArticles = new List<dynamic>();
foreach (var article in latestArticlesNode.Children)
{
latestArticles.Add(new
{
title = article.title,
date = article.date.ToString("dd.MM.yyyy"),
content = article.content
});
}
var o = new {
latestArticles = latestArticles
};
string json = Json.Encode(o);
}
window.latestArticlesObj = @Html.Raw(json);
console.log(window.latestArticlesObj);
</script>
The console.log gives me an object, but the "content" field doesn't give me what I want... any suggestions? Date and title fields are just like they should be.
How to render RTE content to a JSON object in macro?
I have created a few macros now that create json objects with their data (I use JS to render that data to the page). Those have been lists of things using simple text fields. But now I have to retrieve data from a RTE field - and I'm experiencing problems doing that.
The console.log gives me an object, but the "content" field doesn't give me what I want... any suggestions? Date and title fields are just like they should be.
Ok, I found out.
should be
is working on a reply...