Is there a way to access array index inside each block helper in meteor blaze?
I am looking for something like this.
{{#each myarray}}
    {{this.arrayIndex3}}
{{/each}}
                I'm afraid there is not yet a standard way to do this, however you can write a helper that maps your array to a list of index / value pairs and iterate over it to display what you want.
JS
Template.myTemplate.helpers({
  myArrayWithIndex: function(){
    return _.map(this.myArray,function(value,index){
      return {
        index:index,
        value:value
      };
    });
  }
});
HTML
<template name="myTemplate">
  {{#each myArrayWithIndex}}
    myArray[{{index}}] == {{value}}
  {{/each}}
</template>
You could also define your own block helper called {{#eachWithIndex}} that would automate this process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With