layouts in expressjs
20,520
I usually set layout to false globally, so I know exactly what layout I use where (so no default layout):
app.set('view options', { layout: false });
Then in my routes I can set a layout per route like so:
res.render('my_page', { layout: 'my_layout' });
Read more about Express layouts and templates engines
Author by
Huy Tran
Updated on July 22, 2020Comments
-
Huy Tran almost 4 years
I want to use 2 layouts for main page and admin page
What should i configure my code to do that?
here is my current code configureapp.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(require('stylus').middleware({ src: __dirname + '/public' })); app.use(express.static(__dirname + '/public')); app.use(express.cookieParser()); app.use(express.session({secret: 'secrect', store: MemStore({ reapInterval: 60000 * 10 })})); app.use(app.router); });
-
alessioalex over 12 years
-
chovy almost 12 yearsexpressjs.com link no longer goes to layout.
-
bendytree over 11 yearsHere's the layout docs for 2.X expressjs.com/2x/guide.html#view-rendering. It looks like layouts disappeared in 3.X and were replaced by includes? github.com/visionmedia/express/blob/master/examples/ejs/views/…
-
Orkun Balkancı over 10 yearsFor express 3.x Layout & Partial support check out github.com/publicclass/express-partials
-
Tien Do almost 9 yearsActually I can't find any page saying about rendering on epxressjs.com now, document is simple and hard to find information. Do they want all us use their training services? :)
-
colecmc over 5 yearsExactly what I needed