Search code examples
javascriptmustache

Mustache function arguments and javascript


Peace of mustache template:

        <span class="frameSpec blackBg">{{#i18n}}Kids{{/i18n}}</span>

Peace of javascript code:

// Preparing data to view
var items = {
            'items': data.matches,
            'i18n' : function(){
               return get_translation(key);
             }
            };
        //--

$("#items").append(Mustache.render(items_template, items));

This doesn't work, key always is undefinded?


Solution

  • This is the fix for my code:

    // Preparing data to view
    var items = {
        'items': data.matches,
        'i18n' : function(){
            return function(key){
                return get_translation(key);
            }
         }
    };
    //--