Pushing info out of template to layout

3,168 views
Skip to first unread message

Matt

unread,
Dec 7, 2010, 9:04:04 AM12/7/10
to Express
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 ');
}});

vision media [ Tj Holowaychuk ]

unread,
Dec 7, 2010, 11:18:10 AM12/7/10
to expre...@googlegroups.com
looks fine, whatever works for you :)


--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.




--
Tj Holowaychuk
Vision Media
President & Creative Lead
Reply all
Reply to author
Forward
0 new messages