Experimenting with latest ExpressJS, Jade view engine, NodeJS.
When I render the content template into a default layout (e.g.
mycontent1.jade into layout.jade) I sometimes need the ability to
override/add script tags, metatag stuff etc.. I want to do from the
view rather than the controller for several reasons.
Here's what I've come up with so far for handling adding additional JS
resources from the content template. I want to get your opinion, I
could be going about this completely wrong.
mycontent1.jade
------------
- scripts.push('mycontent1-specific.js');
div
section
h1 Test
aside
p side menu
layout.jade
----------
!!! 5
html(lang="en")
head
title Experiment
link(rel="stylesheet",type="text/css",href="http://
yui.yahooapis.com/3.2.0/build/cssreset/reset-min.css")
- renderScriptTags(scripts)
app.js
----------
app.set('view options', { locals: { scripts: ['universal.js'] }});
// yes will move to requirejs or yui loader etc..
app.helpers({ renderScriptTags: function(scripts) {
return scripts.map(function(script) {
return '<script src="scripts/' + script + '"></script>';
}).join('\n ');
}});