Set page title from a child template in Jade

Set page title from a child template in Jade

Problem

I’m wanting to set my page titles in the child templates of the layout via jade. I don’t want to set them in the routes since that requires a server restart. Here’s what I’m hoping to accomplish:

layout.jade:

!!! 5
  head
    - var title = title || "Default Title Here"
    title #{title}
    // ...

child.jade:

- var title = "Child Title Here"
extends layout
// ...

Any thoughts on how I can accomplish this would be a great help.

Thanks!

Problem courtesy of: Dan

Solution

From https://github.com/visionmedia/jade/issues/654#issuecomment-5859502

layout.jade

block variables
!!! 5
head
 - var title = title || "Default Title Here"
 title #{title}

child.jade:

block variables
  title = "ST"
extends layout
Solution courtesy of: schaitanya

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *