Back to topic list

Helper – Grouped each

@!helper @!block helper @!templates

grouped_each helper provides way to split long array into smaller arrays of specified length.

Usage

{{#grouped_each :size_of_chunks :context}}

Use case

grouped_each comes handy when you have a list of, say, 30 items and you want to display them 3 at a time. grouped_each will split the list of 30 items into 10 lists of 3 items and provides each list of 3 items as {{this}}.

{{#grouped_each 3 global.documentation_list}}
    {{#each this}}
        <div class="col-md-4">
            columns
        </div>
    {{/each}}
        <div class="wedge"></div>
{{/grouped_each}}

Shout out

Thanks @Timothy Robertson of https://funkjedi.com/technology/412-every-nth-item-in-handlebars/ for providing the idea and base implementation.

Back to topic list

Shout out to pexels and freepik