I'm trying to get Scriban to ignore errors when parsing a template, so it will partially format.
For instance
var template = Template.Parse("{{foo}} {{bar.}}");
template.Parse(new { foo = 1 });
This throws an InvalidOperationException
. What I want to get is something like
1 {{bar.}}
or
1 ERROR
Is there any way to do that?
Currently, I'm doing this:
try
{
var template = Template.Parse(input);
return template.Render(variables);
}
catch (Scriban.Syntax.ScriptRuntimeException ex)
{
return input;
}
catch (InvalidOperationException ex)
{
return input;
}
But that gives me the whole string without any replacements if there is an error.
I want to handle this in my code, rather than customizing the template, because we're effectively using Scriban "backwards". Our users will be writing simple templates to be filled in with predefined values.