I can loop through children like this:
{{ for i_child in i_datasource.children}}
But what if I only want the first 2, or if I want to skip the first 2 and take the next 3? Is this possible in scriban?
Yes, there are options to create loops like this in scriban:
offset
parameterThis is the scriban equivalent of .Skip()
in .net. It allows you to start the iteration of the loop by skipping the number of entries specified:
{{~ for i_child in i_datasource.children offset:2 ~}}
// display something
{{~ end ~ }}
limit
parameterThis is the scriban equivalent of .Take()
in .net. It limits the number of items iterated through in the loop.
{{~ for i_child in i_datasource.children limit:2 ~}}
// display something
{{~ end ~ }}
You can also use these together:
{{~ for i_child in i_datasource.children offset: 2 limit:4 ~}}
// display something
{{~ end ~ }}
Scriban loop language reference: https://github.com/scriban/scriban/blob/master/doc/language.md#95-loops