TransWikia.com

Using Model in Scriban template

Sitecore Asked on November 7, 2021

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

One Answer

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.

Answered by Dawid Rutkowski on November 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP