Sto provando a scrivere un helper condizionale if statement per Handlebars.js. Essenzialmente, voglio mettere una classe "attiva" su un collegamento se è la pagina Apply Now
.Assistente "if statement" condizionale per Handlebars.js
Helper:
Handlebars.registerHelper('isApplyNow', function(block) {
if(this.title == "Apply Now") {
return block(this);
} else {
return block.inverse(this);
}
});
E Template:
<ul>
{{#each pages}}
<li>
{{#isApplyNow}}
<a href="{{url}}" class ='active'>{{this.title}}</a>
{{else}}
<a href="{{url}}">{{this.title}}</a>
{{/if}}
</li>
{{/each}}
</ul>
Ma, mi stanno un molto scarno javascript errore:
Uncaught [object Object] in handlebars-1.0.0.beta.2.js:595
chiunque può vedere se sto scrivendo questo in modo improprio?
Grazie!
articoli referenziati:
Calling Helper Within If Block in Handlebars Template
http://thinkvitamin.com/code/handlebars-js-part-2-partials-and-helpers/
Ahh duh, ci proverò un po 'quando tornerò su quel lato dell'app. Grazie! – wart
Ecco fatto! Grazie kaptron – wart