Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
7

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.


[#47586] Tuesday, February 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kenyamelinad

Total Points: 339
Total Questions: 85
Total Answers: 116

Location: Marshall Islands
Member since Sun, Aug 29, 2021
3 Years ago
;