Adding offset to {{@index}} when looping through items in Handlebars

前端 未结 9 1027
逝去的感伤
逝去的感伤 2020-12-24 01:20

I\'m iterating over a list in Handlebars using the built-in each helper. Within the each block, I\'m referencing the current loop index

9条回答
  •  猫巷女王i
    2020-12-24 02:03

    Throwing my solution in here. CSS counters.

    body {
      counter-reset: section;                     /* Set a counter named 'section', and its initial value is 0. */
    }
    
    h3::before {
      counter-increment: section;                 /* Increment the value of section counter by 1 */
      content: counter(section);                  /* Display the value of section counter */
    }
    

    I was stuck on this and it was a nicer solution compared to adding a new helper.

提交回复
热议问题