Each and With There are also two Spacebars built-in helpers, {{#each}}, and {{#with}}, which we do not recommend using (see use each-in below). These block helpers change the data context within a template, which can be difficult to reason about.
How about this case? (we care about <ul>):
+with games
ul
+each game in this
li {{game.name}}
else
| Not Found
or we have strange code without {{#with}}
+let tmp_games=games
+if tmp_games
ul
+each game in tmp_games
li {{game.name}}
else
| Not Found
Template.registerHelper('$tpl', function () {
return Template.instance();
});
You can do {{$tpl.useThisInsteadOfHelper arg1 arg2}} or {{$tpl.someState.get}} inside of the templateName html file. This means that your functions can call each other, store state on the template instance without calling Template.instance() everywhere, and aren’t run everytime anything in the data context changes (if you want the function to rerun whenever anything in the data context changes you have to explicitly call Template.currentData()). This gives waaaay more flexibility.
Using the {{#with }} wrapper console.log will return {user: {name: ... }}; without it it will return {users: [{name: ...}]} and you won’t know which user from the list you clicked on.
Is there a way to add the user to the context with {{#let }} instead? The other way I found to do it is add a data attribute to the span an retrieve it from the event.target.dataset but then it turns into a string and feels wrong. Sometimes I still need access to other objects from the outer context and then it turns into a monstrous {{#with user=user users=users foo=foo }}.