.net-corescriban

Issue with providing data model to template with scriban on .net core


I am trying to generate a document from scriban template but no data is present in the output:

var template = Template.Parse("{{model.Data}}");
var renederdContent = template.Render(new {
        model = new {
            Data = "some string"
        }
    });

Yet the output is empty. This used to work perfectly on .net framework whereas on .net core I've got a problem.


Solution

  • It seems the behavior of Scriban is different here in .net core. It changes names by default to a different case. For instance "Data" is changes to "data" and "PriceChanged" changes to "price_changed". To left the names unchanged you need to call Render method like this:

    var renederedContent = template.Render(new {
        model = new {
            Data = "some string"
        },
        m => m.Name
    });