Concatenating a variable + string in Jade file Concatenating a variable + string in Jade file express express

Concatenating a variable + string in Jade file


use #{} notation if you want to interpolate a variable in the contents of an element. you can just use the variable names straight up if you want to use them in attributes.

link(rel='stylesheet', href='/stylesheets/' + pref + '.css')

equivalent:

link(rel='stylesheet', href='/stylesheets/' + locals.pref + '.css')

when to use #{}:

a(href='/stylesheets/' + locals.pref + '.css') View the stylesheet at #{pref}


Jade files are compiled in Node.js env.

Node.js (from v4.0.0) supports template literals, so

link(rel='stylesheet', href=`/stylesheets/${pref}.css`)

equivalent:

link(rel='stylesheet', href='/stylesheets/' + pref + '.css')