68
rated 0 times
[
71]
[
3]
/ answers: 1 / hits: 8198
/ 11 Years ago, tue, january 7, 2014, 12:00:00
I'm just starting to learn Handlebars.js, I used the Handlebars.js site (http://handlebarsjs.com/expressions.html) to help write this following snippet here:
var story = {
url: www.nytimes.com/colonizemars.html,
text: We finally colonized mars!
};
Handlebars.registerHelper('link', function(object) {
return new Handlebars.SafeString(
<a href=' + object.url + '> + object.text + </a>
);
});
var theTemplateScript = $(#header).html();
var theTemplate = Handlebars.compile (theTemplateScript);
var temp = theTemplate(story);
console.log(temp);
$(function() {
$(document.body).append (temp);
});
Not sure why I get the following error when I run it:
Uncaught TypeError: Cannot read property 'url' of undefined
Thanks!
More From » jquery