0

I am using jade template to generate a html email, so I need to retrieve the html content by compiling the jade template. However I would need to pass in variable into the email content, so I have the following codes:

users.js:

var fn = jade.compileFile(__dirname + '/../templates/welcomeEmailTemplate.jade');
var html = fn({base_link:'http://something/'});

and then the welcomEmailTemplate.jade looks like:

img(src= !{base_link} + "image.jpg")

but this gives the error of:

Unexpected token }

on the above line in jade template file.

What should be the correct way to pass in variable in jade.compileFile?

Thanks!

jamesdeath123
  • 4,268
  • 11
  • 52
  • 93

1 Answers1

1

You're mixing up two different syntax. You need to do either this:

img(src=base_link + "image.jpg")

or this

img(src="#{base_link}image.jpg")
laggingreflex
  • 32,948
  • 35
  • 141
  • 196
  • img(src="!{base_link}image.jpg") doesn't seem to work? the rendered html shows ) straight out. – jamesdeath123 Oct 11 '15 at 01:35
  • Try `#{base_link}` that would work. [`#{}` is for escaped string, `!{}` for unescaped](http://stackoverflow.com/questions/8698534/how-to-pass-variable-from-jade-template-file-to-a-script-file/28310031#28310031). I guess `!{}` doesn't work inside quotes – laggingreflex Oct 11 '15 at 17:58