5

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?

1 Answer 1

5

Yes, there are options to create loops like this in scriban:

The offset parameter

This 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 ~ }}

The limit parameter

This 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.