Node.js express the given name

How to set page / route header using express and jade?

+8
source share
4 answers

simple.jade:

!!! 5 title= title 

Express application:

 app.get('/simple',function(req,res) { res.render('simple',{title='mytitle'}); } 
+9
source

Specifying the page name in the route is the easiest way.

This example shows the index.js file in my routes .. folder, which Express is installed by default.

 /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Page Title' }); }); 
+3
source

This is what I did, and it worked for me. The example uses a hypothetical representation of β€œvideo,” which requires a title that should be a β€œvideo gallery,” adjust accordingly.

layout.jade // This is added by default in express applications

 doctype html html head title= title link(rel='stylesheet', href='/stylesheets/style.css') body block content 

video.jade // You can create a view like this

 extends layout block content h1= title 

app.js // The default file, but you must add such a route. And set the title

 app.get('/videos/', function(req, res){ res.render('videos', { title: 'Video Gallery' }); }); 
+1
source

On your server (app.js):

 app.set('title', 'My Site'); 
0
source

All Articles