queckezz/koa-views

Question: global variable in view file

raphaelsoul opened this issue · 2 comments

How can I access ctx in a view file?
For example, I want to visit ctx.state.user in a .hbs file.
is there some way globally passing some value? Thanks

What do you mean global variable? Does await ctx.render('user.hbs', { user: ctx.state.user }) work for you?

my bad. I use passport to authenticate my visitors. And I found I can use {{ user }} to access my ctx.state.user.