Last active
August 29, 2015 14:02
-
-
Save torgeir/e93699bc10d015b6902f to your computer and use it in GitHub Desktop.
Hogan internal access nested context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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