Skip to content

Instantly share code, notes, and snippets.

@torgeir
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torgeir/e93699bc10d015b6902f to your computer and use it in GitHub Desktop.
Save torgeir/e93699bc10d015b6902f to your computer and use it in GitHub Desktop.
Hogan internal access nested context
<!doctype html>
<meta charset=utf-8>
<title>hogan internal access nested context</title>
<script src="hogan-3.0.1.js"></script>
<script>
var data = {
site: {
heading: "Site heading",
sections: [
{ title: "Section 1" },
{ title: "Section 2" },
{ title: "Section 3" }
]
}
};
var template = [
"{{#site}}",
"<h1>{{heading}}:</h1>",
"<ul>",
"{{#sections}}",
"<li>{{title}} - {{heading}}</li>",
"{{/sections}}",
"</ul>",
"{{/site}}"
].join('');
var html = Hogan.compile(template).render(data);
console.log(html);
// <h1>Site heading:</h1>
// <ul>
// <li>Section 1 - Site heading</li>
// <li>Section 2 - Site heading</li>
// <li>Section 3 - Site heading</li>
// </ul>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment