I am running Express 3.0 with Jade template engine. I'm trying to pass a variable from a template page to the main layout page. Like this:
!!! 5
html(lang='en')
head
meta(charset='utf-8')
title= locals.title
- if (typeof(stylesheets) !== 'undefined')
each stylesheet in stylesheets
link(rel='stylesheet', href='/stylesheet/#{stylesheet}.css')
body
block body
stylesheets = ["landing"]
extends layout
block body
h1 Test 1234
The generated code does not include the extra stylesheet tag. I tried - var stylehseets...
and renaming 'stylesheets' fearing it might be a keyword.
Any suggestions?
Use the block append feature for this. Straight from the docs is an example exactly like what you are trying to do.
layout.jade
html
head
block head
link(rel='stylesheet', href='/css/layout.css')
body
block body
landing.jade
extends layout
block append head
link(rel='stylesheet', href='/css/landing.css')
block body
h1 Test 1234