I understand each and collection helper methods are two possible ways to iterate over a list of items in my handlebars templates. I am looking for some practical advice about when to use each or collection and what are the differences between the two methods.
I understand each and collection helper methods are two possible ways to iterate over
Share
Each:
corresponding HTML
Collection:
corresponding HTML
As you can see both deal with arrays. In a nutshell
eachis used to display an array of elements whilecollectionis used to display an array of viewsThe main difference comes in practical use is when you want to interact with elements. If you just want to display a list of array use
eachhelper.But if you want to interact with each of the element in the array while maintaining context of the clicked element you
collectionsLet me explain with an example
I think this clears your doubt…