0

I started using mustache and want to know how to load different parts of a template. Like this.

require(['jquery','stache!templates/message'], function($, template) {
 'use strict';

var person1 = {
    firstName: "John",     
};
$('#container1').html(template(person1))

var person2 = {
    lastName: "Petersen",       
};
$('#container2').html(template(person2))

});

And the html template message.html.

This should only loaded in container1

<h1>{{firstName}}</h1>

This should only loaded in container2

<h1>{{lastName}}<h2>

How can I do that?

Newcoma
  • 799
  • 4
  • 13
  • 31
  • Can you post the full template in message.html? – adamesque Jan 18 '14 at 22:40
  • The full template is those two lines with first and last name. – Newcoma Jan 18 '14 at 22:44
  • 1
    So it should be two separate templates. Template can be applied only as whole in mustache. – c-smile Jan 18 '14 at 22:58
  • Yup impossible. Must be separate templates. If you need conditional inclusion of parts of the template I believe [this link](http://stackoverflow.com/questions/6027525/how-do-i-accomplish-an-if-else-in-mustache-js) is interesting. – webketje Jan 18 '14 at 23:56

0 Answers0