89
rated 0 times
[
95]
[
6]
/ answers: 1 / hits: 6592
/ 10 Years ago, wed, february 19, 2014, 12:00:00
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);
More From » jquery