[ 4 posts ]

Daniel Ji

  • Username: humblepie
  • Joined: Tue Feb 28, 2012 10:30 am
  • Posts: 147
  • GitHub: humblepie
  • Gists: humblepie
  • Offline
  • Profile

Handlebar each helper

Post Posted: Thu May 17, 2012 2:08 pm
+0-
Hi!

I was wondering if there's a way to know the current index of the iteration when using the #each helper. Something like accessing the {{currentIndex}} value shown below.

Code:
{{#someArray}}
     {{currentIndex}}
{{/someArray}}


As a last resort, I'm thinking I might just have to add an index attribute to each of the objects in the array that the #each will be iterating over.

Thanks.

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile

Re: Handlebar each helper

Post Posted: Fri May 18, 2012 6:54 am
+0-
It does not supply the index to an `{{#each}}` block:
https://github.com/wycats/handlebars.js ... ase.js#L59

Daniel Ji

  • Username: humblepie
  • Joined: Tue Feb 28, 2012 10:30 am
  • Posts: 147
  • GitHub: humblepie
  • Gists: humblepie
  • Offline
  • Profile

Re: Handlebar each helper

Post Posted: Fri May 18, 2012 9:44 am
+0-
Hi there,

Oh well, that's not a big deal. There's a perfectly suitable (and perhaps cleaner) workaround, which I stated above.

Thanks for responding, Eric.

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile

Re: Handlebar each helper

Post Posted: Fri May 18, 2012 10:52 am
+0-
Yeah, I agree.

The limitations imposed by Handlers are good at keeping one from putting too much logic/coding in their templates.
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum