Last active
August 29, 2015 13:56
-
-
Save myndzi/8985931 to your computer and use it in GitHub Desktop.
Generically pass a config object into the body of an HTML document rendered by Dust
This file contains hidden or 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
// in the app setup: | |
dust.helpers.config = function (chunk, ctx, bodies, params) { | |
var data = ctx.get('config'); | |
if (!data) return chunk; | |
var str = JSON.stringify(data).replace("</script>", "<'+'/script>"); | |
str = "<script>function CONFIG() { return JSON.parse('"+str+"'); }</script>"; | |
return chunk.write(str); | |
}; | |
// in the template: | |
{@config/} | |
// in the controller: | |
res.render('template', { | |
config: {/*whatever*/} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment