Too Much Indentation When Rendering a Scriban Template
YI have this little Scriban template for generating a simple C# class:
You can see the indentation for property declarations is 4 spaces, yet when I render the template, I get this:
where we have an indent of 8 spaces for the properties, and extra empty lines between the properties. What can I do to set the indentation or formatting for this template?
3 Replies
Try playing around with whitespace control
tl;dr for all the
{{ }}
on their own lines, you'll have to use {{~ ~}}
to strip the whitespace properlyThank you for all your very helpful suggestions. I couldn't get any of the whitespace control working, except for
public class {{model.Name -}}
, where the minus sign causes the extra blank line after the public class <className>
, but for the indentation, I had to reduce that from 4 to 2 spaces in my template, so now the template renders 4 spaces, like I want, not the 8 it was rendering. It's somehow doubling the indent size.
Scriban is by default set to autoindent, and the section of the docs about indentation says there is an option to set TemplateContext.AutoIndent
to true, but I can't find how to apply the TemplateContext
object to my tempate's parsing or rendering. I have cloned the Scriban source and will later hopefully figure this out with that as a reference, but for now I have things basically working and can get on with other stuff first, before bothering about the prettiness of my generated class.