Getting Mongo within template helpers


I have this in my template:

<canvas id={{radarchart}}></canvas>

and this javascript:

  radarchart: + "radar",

I’m using charts.js and need to give every item rendered by {{#each... its own id or it won’t work (I think it’s obvious why, but I can explain if that helps). I can’t just use {{_id}} in the template because I have multiple charts to render for each item so I’ve appended radar in the example.

How would I get the current item’s _id from Mongo within a helper like this?

Also, is this the best way to deal with giving each item its own unique id?

Edit: more info

I’m using document.getElementById( + "radar") to select the element for the chart to be rendered.


To start with, your helper needs to be a function that returns a value.


If you are looping through an each, and just need unique ids, you can do:

{{#each template in templates}}
  <canvas id="{{@index}}-myCanvas"></canvas>


@vigorwebsolutions That is perfect and elegant, thanks!!!