Skip to content

Instantly share code, notes, and snippets.

@jincod
Created August 21, 2013 17:20
Show Gist options
  • Save jincod/6297294 to your computer and use it in GitHub Desktop.
Save jincod/6297294 to your computer and use it in GitHub Desktop.
Hogan.js bug during render list with helper
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hogan.js bug</title>
</head>
<body>
Expected:
<div>
Value1 <span><b>first,Value1 </b><b>second,Value1 </b><b>third,Value1 </b></span>
</div>
But was:
<div id="id1"></div>
<script src="http://twitter.github.com/hogan.js/builds/2.0.0/hogan-2.0.0.js"></script>
<script>
var tmpl = Hogan.compile("{{SimpleKey}} <span>{{#list}}{{#Helper1}}{{title}},{{SimpleKey}} {{/Helper1}}{{/list}}</span>"),
context = {
list: [
{
title: "first"
}, {
title: "second"
}, {
title: "third"
}
],
SimpleKey: "Value1",
Helper1: function() {
return function(text) {
return "<b>" + text + "</b>";
};
}
};
document.getElementById("id1").innerHTML = tmpl.render(context);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment