I'm trying to generate an option set where I can select the selected option but I'm not able to access to timeSpent when I nest the Helpers like in the examples above:
This is how I send data to my handlebars template:
{
feed : {
foodMinutes : 90,
timeSpent : 72
}
}
This is where I generate my select option, I thought there was a way like ../timeSpent to get parent data but it doesn't work:
<select>
{{#count feed.foodMinutes 1 0}}
{{#equal ../timeSpent this}}
<option value="{{this}}" selected>{{this}} minuti</option>
{{else}}
<option value="{{this}}">{{this}} minuti</option>
{{/equal}}
{{/count}}
</select>
These are my helpers:
Handlebars.registerHelper("count", function(count, step, start, block) {
var accum, steps, startFrom;
accum = "";
steps = step || 1;
startFrom = start || 0;
for(var i = startFrom; i < count; i += steps) {
accum += block.fn(i);
}
return accum;
});
Handlebars.registerHelper("equal", function(lvalue, rvalue, options) {
if (arguments.length < 3) {
throw new Error("Handlebars Helper equal needs 2 parameters");
}
if (lvalue != rvalue) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
So how can I get the parent data inside an Handlebars Helper scope?