Scriban is a templating language for parsing text documents in .NET.
Questions tagged [scriban]
32 questions
3
votes
1 answer
Scriban - list parsed expressions (variables)
I'm wondering how to list all parsed expressions (variables) by using a simple code snippet:
var template = Template.Parse(@"
-
{{ for product in products }}
-
{{ product.name }}
Price: {{…

Radek Uhlíř
- 79
- 1
- 1
- 9
2
votes
1 answer
How do you parse booleans in Scriban?
Is it possible to perform bool.parse or similar operations?
Simplified Scriban template to demonstrate question:
var template = Template.Parse("{{ $parsed = foo | bool.parse }}");
var result = template.Render(new { foo = "True"});
This throws the…

Bryan Euton
- 919
- 5
- 12
2
votes
0 answers
Remove indentation from multi-line text in scriban template
We use scriban templating engine in my team. I am having trouble finding the resource which can help in resolving the following issue:
In this scenario I would like to indent the echo statements(this is simplifying the problem for the sake of this…

Kiran
- 56,921
- 15
- 176
- 161
2
votes
1 answer
Validating properties in dynamic objects
I am using Scriban to render html templates for a mail service.
Scriban allows me to render html, using an object and a html template like the one below:
- \n
Name 2: {{ model.Username }}
\nMessage 2: {{ model.Password…

Bille
- 371
- 6
- 15
1
vote
0 answers
How do I setup Scriban on VSCode for code generation?
I would like to use Scriban as a code generator and VSCode as an editor. Ideally, I would like Intellisense and syntax coloring for editing templates along with the ability to generate and preview the output on save. Unfortunately,there's a dearth…

ATL_DEV
- 9,256
- 11
- 60
- 102
1
vote
2 answers
Scriban function to convert snake case to pascal/camel case
I'm trying to generate some C# code using Scriban templates. The DB I'm using is postgresql, so my tables and properties are all in snake_case. I managed to make a function to convert snake case to pascal case:
{{ for word in EntityName |…

Spacebar
- 23
- 6
1
vote
0 answers
What is the difference between a Dictionary and a ExpandoObject casted as a Dictionary that prevents Scriban Template Render from working?
Ir am trying to render content that is loaded from a CSV with Scriban. Unfortunately, its not rendering correctly unless I explicitly call ToDictionary to create another dictionary and I would like to understand why, and proper ways to fix it.
var…

jmerkow
- 1,811
- 3
- 20
- 35
1
vote
1 answer
Format HTML in Scriban
using scriban with SXA we notice the generated HTML has a lot of white spaces ex :
This is because in scriban we have if condition before rendering the div with id=de2 , is there a way to format the…

user1534066
- 141
- 5
1
vote
2 answers
How to include another Scriban template in a template as partial?
I have a Scriban template, but I want to use partials to include them in the template. How do I include them?

A. Gh
- 631
- 9
- 24
1
vote
1 answer
How to use array.filter in Scriban?
I have a created a template in a .scriban file, but it doesn't seem to work.
This is the snippet of the array I want to filter:
{{~ somevar = SomeArray | array.filter sub(sv) | array.first ~}}
And the custom function that should be called…

A. Gh
- 631
- 9
- 24
1
vote
1 answer
Scriban Template Engine Multi loop Supports
I am trying to use Scriban Template Engine for multiple loop support.
For Example
string bodyTextSub = "{{ for service in services }} ServiceName: {{ service }} {{ end }}" +
"{{ for subservice in subServiceList }} SubServiceName: {{…

user2911592
- 91
- 12
1
vote
0 answers
How do I get data from a query datasource field in Sitecore using Scriban?
I have a query datasource field, and I want to access the data from within that field.
I have tried things like:
{{ for i_data in (sc_query i_page 'query:{{ i_page.NameOfField }}') }}
{{ i_data.Title }}
{{end}} and{{…

Danny
- 77
- 1
- 8
1
vote
3 answers
Render scriban template from json data
I would like to render a Scriban template with an ExpandoObject or any other data type that can be generated from a JSON string:
var json = "....";
var dyn = JsonConvert.DeserializeObject(json);
var…

Marc
- 12,706
- 7
- 61
- 97
1
vote
1 answer
Issue with providing data model to template with scriban on .net core
I am trying to generate a document from scriban template but no data is present in the output:
var template = Template.Parse("{{model.Data}}");
var renederdContent = template.Render(new {
model = new {
Data = "some string"
…

mr100
- 4,340
- 2
- 26
- 38
0
votes
1 answer
Ignoring errors in Scriban
I'm trying to get Scriban to ignore errors when parsing a template, so it will partially format.
For instance
var template = Template.Parse("{{foo}} {{bar.}}");
template.Parse(new { foo = 1 });
This throws an InvalidOperationException. What I want…

RoadieRich
- 6,330
- 3
- 35
- 52