Handlebars has a built-in helper called lookup
. The documentation is not very clear about how it works. Could I see an example?
Sure, past me! Here's an example from your future.
Suppose you have an object or array obj
and a variable field
and you want to output the value of obj[field]
, you would use the lookup helper {{lookup obj field}}
.
The code defining the helper is simply:
function(obj, field) {
return obj && obj[field];
}