2

Is it possible to perform bool.parse or similar operations?

Simplified Scriban template to demonstrate question:

var template = Template.Parse("{{ $parsed = foo | bool.parse }}");
var result = template.Render(new { foo = "True"});

This throws the error: (1,25) : error : Object bool is null

Bryan Euton
  • 919
  • 5
  • 12

1 Answers1

1

Unfortunately there isn't a way parse booleans with a built in function. One work around is to do the following:

var template = Template.Parse("{{ if foo | string.downcase == `true`; $parsed = true; end; $parsed; }}");
var result = template.Render(new { foo = "True"});

Here is a link to the issue in github: https://github.com/lunet-io/scriban/issues/243.

Bryan Euton
  • 919
  • 5
  • 12