vamsiampolu vamsiampolu - 3 months ago 54
Jade Question

Error unexpected text when using jade

This is the error in my jade template:

Error: E:\Do\hello_express\node_notes\views\simple.jade:6
4| meta(charset="utf-8")
5| meta(name="viewport",content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no")
> 6| meta(http-equiv="X-UA-Compatible",content="IE=edge")
7| title= #{title}
8| link(rel='stylesheet',href='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css')
9| link(rel='stylesheet',href='stylesheets/notes.css')

unexpected text
t


My template looks like this:

html
head
meta(charset="utf-8")
meta(name="viewport",content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no")
meta(http-equiv="X-UA-Compatible",content="IE=edge")
title= #{title}
link(rel='stylesheet',href='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css')
link(rel='stylesheet',href='stylesheets/notes.css')
script(type='text/javascript',src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js')
script(type='text/javascript',src='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js')
body
block content

Answer

The error would be due to the title element rather than the meta being pointed to.

For it, you'll either want to use tag= or #{...}, but not both on the same element.

title= title
title #{title}

The 1st form expects the content that follows the = to be a valid JavaScript expression, which #{...} isn't currently considered.

The 2nd form instead treats the content as plain text, with the exception of #{...} sections that Jade allows for interpolating/inserting the results of code.