I am try to use mustache.js for templating but my basic code is not working Pls help where I m going wrong-
var person = {
firstName: "Christophe",
lastName: "Coenraets"
};
var template = "<h1>{{firstName}} {{lastName}}</h1>";
var output = Mustache.render(template, person);
document.getElementById('result1').innerHTML = output;
The above code is working but the below code is not working :-
This line is written in my .html page:
<script id="sample_template" type="text/template">
<h1>{{firstName}} {{lastName}}</h1>
</script>
This line is written in my .js file:
var data ={
firstName: "Christophe",
lastName: "Coenraets"
};
var template = $('#sample_template').html();
//console.log(template); this prints the html content in console
var info = Mustache.to_html(template, data);
$('#result1').html(info);
I got the solution i have both mustache server side and client side and the problem i describe above is that when i try to fill the placeholders at client side then those placeholder are already consume at server side(becoz i didn't sperate file which has to render server side and whom to render client side ). So their is no placeholder while rendering on client side so only i got html tags will display.
From the documentation, it seems that .to_html() is deprecated...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With