mustache js how to use partials in html

Solutions on MaxInterview for mustache js how to use partials in html by the best coders in the world

showing results for - "mustache js how to use partials in html"
Jakob
10 Jun 2017
1example you have these in your html:
2
3<script type="text/html" id="ul-template">
4    <ul id="list">
5        {{> li-templ}}
6    </ul>
7</script>  
8
9<script type="text/html" id="ul-template2">
10    <div id="list2">
11        {{> li-templ}}
12    </div>
13</script>    
14
15<script type="text/html" id="li-templ">
16    <p>{{ name }}</p>
17</script>  
18
19Here's some jQuery to do just that:
20
21var view = {"name" : "You"},
22li = $('#li-templ').html(), 
23partials = {"li-templ": li},
24ul1 = Mustache.to_html($('#ul-template').html(), view, partials),
25ul2 = Mustache.to_html($('#ul-template2').html(), view, partials);;
26
27document.write(ul1, ul2);
28