How do I set the title of a page/route with express and jade?
simple.jade:
!!! 5
title= title
express application:
app.get('/simple',function(req,res) {
res.render('simple',{title='mytitle'});
}
This is what I did and it worked for me. The example uses a hypothetical "videos" view that needs a title to be "video gallery", adjust accordingly.
layout.jade //This is added by default in express apps
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
videos.jade //You can create a view such as this
extends layout
block content
h1= title
app.js //The file is default but you must add a route like this. And set the title
app.get('/videos/', function(req, res){
res.render('videos', {
title: 'Video Gallery'
});
});
In your server (app.js):
app.set('title', 'My Site');
Specifying the page title in the route is easiest method.
This example shows the index.js
file in my routes
folder.. which is the default set by Express.
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Page Title' });
});
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