Search code examples
javascriptbackbone.jsmarionettemustache

How does Mustache populate the variable inside the curly braces in template?


I'm debugging a big Backbone Marionette application and I'm very new to it. It's also using MustacheJS which I just heard today. I found the template file which has the filename UserProfile.mst

// This is  UserProfile.mst
<div class="userProperty">
  <span>{{ text.Update }}</span>
</div>

I also found the .js file that pulls this template file. It's actually RequireJS that's pulling it.

define([
  'UserProfile.mst'
],
function(UserViewTemplate) {

var obj = {
  "userItem" : {
    "template": UserViewTemplate
  }
};

return obj;
});

However, what I can't figure out is where to find text.Update


Solution

  • Input data that gets populated contains something like

    text : {
            "Update": "Update it!",
            ...
        }
    

    Check "Sample 6: Nested Objects" in http://coenraets.org/blog/2011/12/tutorial-html-templates-with-mustache-js/

    You can use the dot notation to access object properties.