baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax
http://ectjs.com
MIT License
625 stars 69 forks source link

How can I access express "req" inside template? #56

Closed juanmaia closed 8 years ago

juanmaia commented 10 years ago

I'm using ect with express. Is it possible to access req.session inside a template? <%- req.session.user %> or <%- @req.session.user %>

igorkova commented 10 years ago

I can't access ANY locals var inside template.

Ok, now I see: https://github.com/baryshev/ect/issues/34 so it's known issue apparently

juanmaia commented 10 years ago

@igorkova you just need to prefix all locals inside a template with @.

yuri-karadzhov commented 10 years ago

It's express question. You can access it trough locals:

app.use(function(req, res, next) {
  res.locals.req = req;
  return  next();
});

But you probably do not need all req, so you can pass whatever you want. Look trough express issue if will have any troubles with session.