scriban / scriban

A fast, powerful, safe and lightweight scripting language and engine for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty render!

mbasij1 opened this issue · comments

I use this project as my template engine.
Template is
<div class="fontWeight"> <div>{{CompanyTitle}} s</div> <div>{{companyTitle}}</div> <div>{{companytitle}}</div> <div>{{CompanyTel}}</div> </div>
And the model is
{"CompanyTitle":"The Test 4331"}
but the result is
<div class="fontWeight"> <div> s</div> <div></div> <div></div> <div></div> </div>.
I use the online demo too to check that is problem with my code or for engine but results was same and empty!
https://scribanonline.azurewebsites.net/

This online service is prefixing the model with model, so you need to write something like {{model.CompanyTitle}} instead.

hmm!
ok I try
model
{ "companyTitle ": "World"}
and template
Hello {{ model.CompanyTitle }} {{ model.companyTitle }}!
result
Hello !
and try that in my code
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. <input>(75,26) : error : Cannot get the member model.companyTitle for a null object.
in my code some variables without model shows but some of them not showing!

You have a space { "companyTitle ": "World"} at the end of the property name "companyTitle ", remove it and you will see the second {{ model.companyTitle }}!

Thank you for your response
I think in my code it is because of ruby-style variable names!
at last, I change the code to
return template.Render(obj, member => { return System.Text.Json.JsonNamingPolicy.CamelCase.ConvertName(member.Name); });
and everything comes ok in my code!
In my application problem is for two syllable variables!
I can't access CompanyTitle with companyTitle or CompanyTitle or companytitle.
at last, changed the renamer in the render function and everything come ok.
thank you at all.