<script id="entry-template" type="text/x-handlebars-template"> <div class="entry"> <h1>{{title}}</h1> <div class="body"> {{body}} </div> </div> </script>
var source = $("#entry-template").html(); var template = Handlebars.compile(source);
var context = {title: "My New Post", body: "This is my first post!"}; var html = template(context);
Result
<div class="entry"> <h1>My New Post</h1> <div class="body"> This is my first post! </div> </div>
References
http://handlebarsjs.com/
https://www.sitepoint.com/overview-javascript-templating-engines/