<script src="https://rawgithub.com/wycats/handlebars.js/1.0.0/dist/handlebars.js"></script>
<h2>Result is in div below</h2>
<div class="result"></div>
<!-- Your code handlebars template inside this element -->
<template id="template">
Foo: {{foo.bar}}
</template>
//this will get the template code
var templateCode = $("#template").html();
// Handlebars.compile will turn the handlebars code into a function we can invoke later
var template = Handlebars.compile(templateCode);
//this is the context - i.e. the object where handlebars template will resolve its variables from
//feel free to change this object
var context = {
foo: {
bar: 'whatever'
}
};
//this will finally execute the template and return a string - generated HTML code
var htmlResult = template(context);
//this inserts the HTML code into result element
$(".result").html(htmlResult);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.