Reputation: 113
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.
Upvotes: 0
Views: 2062
Reputation: 87
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);
Upvotes: 1
Reputation: 65
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.
Upvotes: 0
Reputation: 1531
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 }));
});
Upvotes: 0