Express always wants to render a 'layout' view

2,359 views
Skip to first unread message

Arunjit Singh

unread,
Aug 6, 2011, 3:07:11 PM8/6/11
to expre...@googlegroups.com
Started using jade with express.

After creating the default app and testing if it worked (which it did), I removed the layout.jade file and put some more content in index.jade and created a new jade template. After running the app again, Express errors out with code 500:

500 Error: failed to locate view "layout"

But the view "layout" is never called! It is simply:
app.get('/', function(req, res){
    res.render('index', {
        title: 'Testing Express'
        body: 'This works fine. Now start making the app!'
    });
});

Does express require a layout.jade view always?

vision media [ Tj Holowaychuk ]

unread,
Aug 6, 2011, 3:16:48 PM8/6/11
to expre...@googlegroups.com
nope it's just a default since most apps will have some common stuff. You just need to pass a local { layout: false }, but there are several ways to do that:

   res.render(view, { layout: false })
   res.local('layout', false)
   app.locals({ layout: false }) // app level default
   app.set('view options', { layout: false }) // pretty much same as above

currently the app-level locals take precedence, and while "view options" reads better I might remove it in 3.x since it's extraneous

--
You received this message because you are subscribed to the Google Groups "Express" group.
To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/XkJ3saoiAt0J.
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

Arunjit Singh

unread,
Aug 6, 2011, 3:27:08 PM8/6/11
to expre...@googlegroups.com
Thanks!
I just re-read the guide on expressjs.com, and found app.set('view options', {layout: false}), which seems to fix layout always wanting to crop up.

App-level locals, app.locals, are always applied to views? Is there a way to make each view have completely independent locals?

--Arunjit

PS: is there a good place to learn about jade? (I'm making syntax errors all over the place)
--A

TJ Holowaychuk

unread,
Aug 6, 2011, 3:28:25 PM8/6/11
to expre...@googlegroups.com
they are just merged, so you can still pass whatever to res.render() per request, but it's nice to have app-level locals too like little date helper functions etc

-- 
TJ Holowaychuk
--
You received this message because you are subscribed to the Google Groups "Express" group.
To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/bHeLHFy9pP4J.
Reply all
Reply to author
Forward
0 new messages