Passing a context variable through an #each block

I’ve got a nested #each loop and the inner loop needs some info from the outer loop. To best explain, here’s the working code (using Meteor v.NEXT from github):

{{#each filteredCollection}} //returns simple array like ["client", "vendor"]
  {{#with idx=@index heading=this}}
    {{#if filteredItems}} ///needs the @index in its helper function
      {{#let heading=heading}}
        {{#each filteredItems}}
          {{#with doc=this heading=heading}}
            {{>filteredItem}} //needs heading & the document

As shown, this works perfectly. I needed to use a #let to permeate the #each block, and then a #with once inside to give it context. This seems really hacky to me, is there a better way to do it?

i had to solve this too. you can use {{ … }} and {{ . }} to refer to the parent and current contexts, respectively. also meteor provides a way to get parent contexts in the template api.

Oh man, time to call it a night, you’re absolutely right I forgot about that. Got rid of the let & used .. in the second #with. Still a little ugly, but it better than before. Cheers!