Newcoma
Newcoma

Reputation: 809

Partials in mustache.js

I'm trying to figure how partials in mustache works.

JS

var mustacheTmpl = Mustache.render(popups, {list:true});

The popup template

{{#list}}
<ul class="pending-job-list">
<li>test</li>
</ul>
{{/list}}

Now I want to put he list inside some markup from the same template (popup) and render it

{{#outer}}
   <div class="outerPopup">
      // I want to render the list inside here
   </div>
{{/outer}}

How do I achieve that ?

Upvotes: 3

Views: 1244

Answers (1)

JVitela
JVitela

Reputation: 2512

Here you are:

var partial = "{{#list}}"+
"<ul class=\"pending-job-list\">"+
"<li>{{.}}</li>"+
"</ul>"+
"{{/list}}";


var template = "{{#outer}}"+
"<div class=\"outerPopup\">"+
"{{>list}}"+
"</div>"+
"{{/outer}}";

var html = Mustache.render(template, { outer: {list:["test"]} }, { list:partial });

Upvotes: 1

Related Questions