4

Is it possible to use the current Model in Scriban?

I have a CutomHeroViewModel

public class CustomHeroViewModel : VariantsRenderingModel
{
    public string HeroTitle { get; set; }
    public string HeroDescription { get; set; }
    public List<string> ImageUrl { get; set; }
}

I would like to use its properties in a Scriban template.

I tried the following code {{ o_model.HeroTitle }} but its showing empty value

Any help or suggestion would be appreciated.

Thanks in advance

6

Yes, it is possible. Keep in mind that Scriban by default is lower casing properties and using underscore to separate the words. So property called VariantFields will be accessible in Scriban by variant_fields. Take a look here:

enter image description here

Please refer to the Scriban documentation for more details: https://github.com/lunet-io/scriban

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy