Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js express set title

How do I set the title of a page/route with express and jade?

like image 758
Harry Avatar asked Mar 18 '11 01:03

Harry


4 Answers

simple.jade:

!!! 5
 title= title

express application:

app.get('/simple',function(req,res) {
    res.render('simple',{title='mytitle'});
}
like image 183
generalhenry Avatar answered Sep 30 '22 18:09

generalhenry


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'
  });
});
like image 32
JGallardo Avatar answered Sep 30 '22 19:09

JGallardo


In your server (app.js):

app.set('title', 'My Site');
like image 30
Jom Avatar answered Sep 30 '22 20:09

Jom


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' });
});
like image 25
paulby Avatar answered Sep 30 '22 18:09

paulby