{{#if}} inside a {{#each}} with a parameter coming from the each item

235 views Asked by At

I have a {{#each}} that's essentially iterating through the users collections. I now wish to check if the user is an admin to set a switch (materialize). A simplified version:

{{#each getUsers}}
    testing: {{_id}}  {{#if isAdmin "tTEScMyjCedano2oT"}}checked="checked"{{/if}}
{{/each}}

Here I am hard coding in the _id parameter in the {{#if}} and it works as expected. The isAdmin function works correctly, the {{#if}} works and the {{_id}} works as well (prints out the correct id).

But of course I do not want to hard code the id passed to isAdmin but want it to be {{_id}} however it doesn't work. i.e.

{{#each getUsers}}
    testing: {{_id}}  {{#if isAdmin "{{_id}}"}}checked="checked"{{/if}}
{{/each}}

does not work and neither does

{{#each getUsers}}
    testing: {{_id}}  {{#if isAdmin "{{../_id}}"}}checked="checked"{{/if}}
{{/each}}

nor

{{#each getUsers}}
    testing: {{_id}}  {{#if isAdmin {{id}}}}checked="checked"{{/if}}
{{/each}}

What is the correct way to do this?

1

There are 1 answers

3
saimeunt On BEST ANSWER

Don't use double quotes nor curly braces :

{{#each getUsers}}
  testing: {{_id}}  {{#if isAdmin _id}}checked="checked"{{/if}}
{{/each}}