Counter for handlebars #each

后端 未结 8 1146
小鲜肉
小鲜肉 2021-02-04 02:29

In Handlebars, say i have a collection of names how can i do

{{#each names}}
{{position}}
{{name}}
{{/each}}

where {{position}} is

8条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 02:46

    Current method,

    Since Handlebars API V2 they already include an @number It's basically an index of the iterator start with 1.

    So, This is what you could have done.

    {{#foreach names}}
    {{@number}}
    {{name}}
    {{/foreach}}
    

    Reference: https://ghost.org/docs/api/v3/handlebars-themes/helpers/foreach/

提交回复
热议问题