Reputation: 777
Is it somehow possible to concat variables in a handlebars expression - for instance in an each?
{{#each foo/cat{{bar.id}}}}
Result of the above should be the same as to write
{{#each foo/cat2}}
Ideas?
Upvotes: 0
Views: 1956
Reputation: 8993
I think if you are having this problem it is a clue that your data structure needs changing. That notwithstanding, I believe there is no way to arrive at a solution without creating a custom helper. I think the simplest way would be to create a helper to concatenate the prefix and the id, and then to use the built-in lookup helper to access the member of foo
:
Handlebars.registerHelper('concat', function(prefix, id) {
return (prefix + id);
});
{{#each (lookup foo (concat 'cat' bar.id))}}
{{/each}}
Upvotes: 1