Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.24k stars 214 forks source link

[Question] Ignore property casing using JSON #490

Closed MarkNL2 closed 2 years ago

MarkNL2 commented 2 years ago

I am trying to make Handlebars to parse my templates with case-insensitive properties.

By default this works fine when using dynamics:

var data = new{
   name = "firstname",
   Lastname = "LastName"
};

Handlebars.Compile("Name: {{Name}} {{LastName}}").Invoke(data)

Result : Name: firstname LastName

But when I use Json as input data the properties seem to be case sensitive:

var data = JsonConvert.DeserializeObject<ExpandoObject>("{name:\"firstname\",Lastname:\"LastName\"}");

Handlebars.Compile("Name: {{Name}} {{LastName}}").Invoke(data);

Result:Name:

I have also tested it with:

How can i get get the same results as C# dynamics with JSON data?


Update note: fixed code blocks

oformaniuk commented 2 years ago

Hello @markkl

You can find explanation for such a behavior (and a potential fix) in the following issue: #362

You may also use JObject directly in combination with Handlebars.Net.Extension.NewtonsoftJson