mercredi 29 juin 2016

how to use handlebars conditional helpers?

I have a Handlebars template with multiple iff blocks. iff is a custom helper for comparing values. The template compiles, but oo applying it i get no output and no errors.

Please what am I doing wrong?

iff helper

Handlebars.registerHelper("iff", function (v1, operator, v2, options) {
    switch (operator) {
        case '==':
            return (v1 == v2) ? options.fn(this) : options.inverse(this);
        case '===':
            return (v1 === v2) ? options.fn(this) : options.inverse(this);
        case '<':
            return (v1 < v2) ? options.fn(this) : options.inverse(this);
        case '<=':
            return (v1 <= v2) ? options.fn(this) : options.inverse(this);
        case '>':
            return (v1 > v2) ? options.fn(this) : options.inverse(this);
        case '>=':
            return (v1 >= v2) ? options.fn(this) : options.inverse(this);
        case '&&':
            return (v1 && v2) ? options.fn(this) : options.inverse(this);
        case '||':
            return (v1 || v2) ? options.fn(this) : options.inverse(this);
        case '!=':
            return (v1 != v2) ? options.fn(this) : options.inverse(this);
        case '!==':
            return (v1 !== v2) ? options.fn(this) : options.inverse(this);
        default:
            return options.inverse(this);
    }
});

template


    
    <div class='sb-date'></div>
    
    
    <div class='sb sb-text sb-'><div class="sb-time"></div></div>
    
    
    <div class='sb sb-text sb-'><div class="sb-time"></div></div>
    
    
    <div class='sb sb-text sb-'><div class="sb-time"></div></div>
    
    
    <div class='sb sb-image sb-'><img alt="" src="media/" /><div class="sb-time"></div></div>
    
    
    <div class='sb sb-file sb-'>media/<div class="sb-time"></div></div>
    


Aucun commentaire:

Enregistrer un commentaire