StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
401 stars 58 forks source link

template for json object #79

Closed herme063 closed 4 years ago

herme063 commented 4 years ago

I need to stub in a json data, how do I do that?

I tried to pass the object as is but it is replaced by the ToString() result. When I pass in a json string instead, all the quotes are escaped (replaced with the html encoded version).

matrix: {
    type: "local",
    store: {
        fields: ["Gender", "Field", "AgeGroup"],
        data: {{Data}}
    },
    leftAxis: {{LeftAxis}},
    topAxis: {{TopAxis}},
    aggregate: {{Aggregate}},
}

and my template object goes as follow

public class Template
{
    public Row[] Data { get; set; }
    public Axis[] LeftAxis { get; set; }
    public Axis[] TopAxis { get; set; }
    public Axis[] Agggregate { get; set; }
}

Ideally I want each one of them to be replaced with a json array.

Romanx commented 4 years ago

Hi there,

This the escaping would be standard mustache. You can un-escape by using {{{.

We call string on any objects that we need to render since this is the simplest way to get the string representation of it.

herme063 commented 4 years ago

works great, thank you!