Closed kislovs closed 5 years ago
Hi there,
Unfortunately the reason for this is due to the fact you're passing a Dictionary<string, object> which means the compilation renderer has no idea of the types you're passing and so can't be sure what it needs to render.
If you convert your JSON into full classes then it should work correctly. This is unfortunately one of the limitations of the compilation renderer since the work is done upfront to make the rendering very fast
Unfortunately, I can't create full classes, because I have no idea what JSON I get, because user defines template, save it and later use that to render that template with requested data.
I have debugged it a little bit and found that method which should create compiled context mismatch nesting level (it should be { caption, src.Item["Param_0"].Item["caption"] }
, but it matches { caption, src.Item["caption"] }
.
(if src.Item["Param_0"]
is for element of array/list)
Btw, I have seen methods for dynamic
, maybe I can use that for my purposes?
Dynamic will have the same problem if you're looking to compile. I'd recommend using the standard renderer if you're not sure about the shape of your input.
Also if you're using JSON I'd suggest looking at Stubble.Extensions.JsonNet which may make it a little easier for you since you can just parse into JObject. Only if you're using JsonNet though
Okay, I will use usual async rendering. It will speed up template rendering and reduce memory usages by 4 times in comparison with library which I used before. So thank you for the library and thank you for fast reply :)
No worries, please let us know if you have any issues!
I have the following template:
and have following data in json
Which look this way as at runtime:
When I use usual
new StubbleBuilder().Build().Render(Template, Context)
, I get this:When I use compilation
I get this:
Why does it work this way?