Handlebars.Net
Handlebars.Net copied to clipboard
{{#JsonEach jsonstring}} helper
I am trying to write a block helper that would parse a Json string to get a dynamic list of objects to use for multiple rows.
I am bring in a master detail view with SQL and the rows are master, but the detail is embedded as JSON in one of the columns.
Here is what I have tried
Handlebars.RegisterHelper("JsonEach", (writer, options, context, args) =>
{
var s = args[0].ToString();
var expConverter = new ExpandoObjectConverter();
dynamic a = JsonConvert.DeserializeObject<List<ExpandoObject>>(s, expConverter);
foreach (var item in a)
options.Template(writer, item)
});
My foreach loop is getting executed properly but it appears that the context never changes. Is it possible to create a new context here? Any other solutions?
Nevermind. it is working great.
This code is being used for email, and I am using PreMailer.Net.PreMailer.MoveCssInline and that was mangling my handlebars before it got to the RenderTemplate. 12 hours of wasted time!