Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layouts in expressjs

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 configure

app.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);
});
like image 805
Huy Tran Avatar asked Jan 09 '12 15:01

Huy Tran


People also ask

What is Express layout?

Express-layout is a middleware that overrides the standard res. render() method.

What is the use of Express EJS layouts?

Today we are going to look at how we can use Express EJS Layouts to help us with website templating which ultimately help us to avoid writing duplicated code as well as making our website / application easily maintainable.

Is ExpressJS good for production?

It's fast, unopinionated, and has a large community behind it. It is easy to learn and also has a lot of modules and middleware available for use. Express is used by big names like Accenture, IBM, and Uber, which means it's also great in a production environment.

Is ExpressJS abandoned?

Some of the most popular packages and projects like Express. js and Sails have been effectively abandoned and left rotting for years now.


1 Answers

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

like image 88
alessioalex Avatar answered Oct 17 '22 20:10

alessioalex