Skip to main content

Configure Scriban

If you'd like to modify Scriban TemplateContext, you can do it with IPostConfigureScribanTemplateContext.

For example:

  • Add new shared function
  • Add utility functions
  • Add new shared values
  • Populate user context
  • Modify member renaming rules
  • etc.
public interface IPostConfigureScribanTemplateContext
{
Task<TemplateContext> ConfigureAsync(TemplateContext context);
}

You can add multiple registrations of IPostConfigureScribanTemplateContext

Example (Member Renamer)

caution

Be careful, built-in types would also be renamed by your renamer.

Startup.cs
services
.AddTemply(x => x
.AddPostConfigureScriban(context =>
{
context.MemberRenamer = (member) => member.Name
}))

OR

MemberRenamerPostConfigureScribanTemplateContext.cs
public class MemberRenamerPostConfigureScribanTemplateContext
{
public Task<TemplateContext> ConfigureAsync(TemplateContext context)
{
context.MemberRenamer = (member) => member.Name;
return Task.FromResult(context);
}
}

Startup.cs
services
.AddTemply(x => x
.AddPostConfigureScriban<MemberRenamerPostConfigureScribanTemplateContext>())