Skip to content

Instantly share code, notes, and snippets.

@myndzi
Last active August 29, 2015 13:56
Show Gist options
  • Save myndzi/8985931 to your computer and use it in GitHub Desktop.
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
// 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