I don't want it to be layout.ejs.
I want to set my layout to be another template for THIS specific controller.
EJS: EJS or Embedded Javascript Templating is a templating engine used by Node.js. Template engine helps to create an HTML template with minimal code. Also, it can inject data into HTML template at the client side and produce the final HTML.
Locals represent server-side data that is accessible to your view—locals are not actually included in the compiled HTML unless you explicitly reference them using special syntax provided by your view engine. <div>Logged in as <a><%= user.fullName %></a>.</
Template Engines and EJS:Template engine is a part of Express that enables us to use static files in our applications. Template engine converts variables to values and changes the template to HTML files to send to the client. The default template engine of Express is Jade, but EJS is the most commonly used engine.
Just set layout property in express app settings.
app.set('layout', 'layouts/layout');
Just pass layout as render locals object.
app.get('/', function(req, res) {
res.render('the-view', { layout: 'specific-layout' });
);
More info here: https://www.npmjs.com/package/express-ejs-layouts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With