Reputation: 7181
So I'm having an problem loading my stylesheets in my express project. When I was using express 2.5.8 my styles were being loaded correctly, but when I updated to 3.x the styles started failing to load. The views get rendered but without any styles.
I'm using node, express 3.x, jade, and bootstrap. My styles are in public/stylesheets/*
.
UPDATE: It seems that for some reason layout.jade
isn't being rendered.
Here' my server.js
require('coffee-script');
/**
* Module dependencies.
*/
var express = require('express'),
flash = require('connect-flash');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('port', 3000);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(flash());
app.use(require('connect-assets')());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
app.configure('test', function () {
app.set('port', 3001);
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
require('./apps/landing-page/routes')(app);
require('./apps/authentication/routes')(app);
require('./apps/home/routes')(app);
require('./apps/register/routes')(app);
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.settings.port, app.settings.env);
Here's my main layout.jade
view:
!!!
html
head
title= title
script(src='http://code.jquery.com/jquery-latest.js')
link(rel='stylesheet', href='/stylesheets/bootstrap.css')
link(rel='stylesheet', media='screen', href='/stylesheets/bootstrap-responsive.css')
link(rel='stylesheet', href='/stylesheets/app.css')
script(src='javascripts/bootstrap.js')
| <!--[if lt IE 9]>
| <link rel="stylesheet" href="stylesheets/ie.css">
| <![endif]-->
| <!-- IE Fix for HTML5 Tags -->
| <!--[if lt IE 9]>
| <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
| <![endif]-->
body
!=body
script(src='javascripts/app.js')
And here's one of my routes:
routes = (app) ->
app.get '/home', (req, res) ->
res.render "#{__dirname}/views/home",
title: 'Home | SiteName'
stylesheet: 'home'
module.exports = routes
Upvotes: 2
Views: 1286
Reputation: 28974
I believe that layout rendering was set to false
per default in Express 3, so try and add following to your configuration:
app.set('view options', { layout: true });
Update: The migration guide state that the concept of layouts and partials have been removed altogether. Instead, use Jade's template inheritance.
/views/layout
!!! 5
head
// all your header elements
body
block content
/views/home
Add the following at the top:
extends layout
block content
// the stuff you want to have in your content block
For more info, take a look at this guide.
Upvotes: 3
Reputation: 26690
app.use(express.static(__dirname + '/public'));
must be before
app.use(app.router);
Upvotes: 2