0

I created a project using express tool "express -s", By default it assign jade as default views templating system.

I have also create a file index.html and i converted it using html2jade tool, the problem is when i try to access index.jade file using this function :

exports.index = function(req, res){ console.log('welcome admin'); res.render('admin/app/index', { }); } 

i got this error

SyntaxError: Unexpected token . at Object.Function (unknown source) 

Please can someone explain what's wrong :)

Thanks in advance.

1
  • 1
    I recommend you use ejs, because you can use html: embeddedjs.com Commented Dec 1, 2012 at 8:02

3 Answers 3

1
That problem seems to be some formatting issue. you can use ejs instead. add the following to your app.js: // map .renderFile to ".html" files app.engine('html', require('ejs').renderFile); // make ".html" the default app.set('view engine', 'html'); //Then you can use below code to render html files and code in ejs: res.render('index.html); 
Sign up to request clarification or add additional context in comments.

Comments

0

That error typically means that there's a problem with the Jade syntax in your template so I would double check that - the output to the terminal should contain more detailed information about where the parsing error occurred.

Also, if you don't already have it configured, I would recommend adding the following to turn on Connect's error handler:

app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); 

Comments

0

It could be that you're not sending any data to the index file. I would try something like this..

 exports.index = function(req, res){ console.log('welcome admin'); res.render('index', { output: 'Welcome Admin' }); } 

And then in your app.js file you want to have

 app.get('/', routes.index); 

and then in your index.jade file should have the tag for output key.so that whatever the value is given to output key is printed in the template.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.