Scriban property access returns empty string

255 views Asked by At

I have a class that looks like this:

public class BomInfo
{
    public string PartNumber { get; set; }
    public string Revision { get; set; }
}

I have Scriban parse and render calls similar to this:

var boms = new List<BomInfo> { new BomInfo { PartNumber = "1234-12345-12", Revision = "A" } };
var output = Scriban.Template.Parse("{{boms[0].Revision}}").Render(new { boms = boms });
Console.Out.WriteLine(output);

I was expecting the output A, but instead I get an empty string. I know you can index lists within Scriban templates, because if I remove the property reference and just use {{boms[0]}} as my template, I get a valid result, the same as calling .ToString() on the object.

Am I doing something wrong, or does Scriban not support this?

1

There are 1 answers

0
RoadieRich On BEST ANSWER

As stated in https://github.com/scriban/scriban/issues/507 and the Scriban Readme,

NOTICE

By default, Properties and methods of .NET objects are automatically exposed with lowercase and _ names. It means that a property like MyMethodIsNice will be exposed as my_method_is_nice. This is the default convention, originally to match the behavior of liquid templates. If you want to change this behavior, you need to use a MemberRenamer delegate

As such, changing the template to {{boms[0].revision}} is required, unless I want to implement a MemberRenamer.