adoconnection / RazorEngineCore

.NET6 Razor Template Engine
MIT License
565 stars 84 forks source link

Property not parsed, when preceded with an escape character #97

Closed JohnBerg60 closed 2 years ago

JohnBerg60 commented 2 years ago

I use the most simple raw example:

IRazorEngineCompiledTemplate template = razorEngine.Compile(raw, builder =>
{
        builder.AddUsing("System");
});

return template.Run(templateVars);

Providing a raw string like this works just fine (notice the space before @ :

"Peripheralheader": "/*\n *\t @Model.Name \n *\tAutogenerated on @DateTime.Now\n */"

When I remove the spaces and run the template with this raw string:

"Peripheralheader": "/*\n *\t@Model.Name \n *\tAutogenerated on@DateTime.Now\n */"

the ouput is uncompiled, and the two vars a not recognized as vars.

adoconnection commented 2 years ago

Well, this is how Razor works. if there is no leading space you supposed to write

Autogenerated @("on" + DateTime.Now)\n
JohnBerg60 commented 2 years ago

And with this:

"Peripheralheader": "/*\n *\t@Model.Name

I do @("\t" + Model.Name) ??

adoconnection commented 2 years ago

yep, thats what documentation suggest

image