Search code examples
vaporleaf

Is it possible to access session value in Leaf?


Is it possible to get session value in Leaf?

As this post suggested, I should be able to access session using #(request.session).

But when I set a value in session:

try request.assertSession().data.set("foo", "bar")

I got nothing using:

#(request.session.foo)

I also tried:

#(foo)
#(session.foo)
#(session.data.foo)
#(request.session.data.foo)

None of them works.

What am I missing? I'm on Vapor 2.4.4 with Leaf Provider 1.1.0.


Solution

  • It is possible to access it - if you pass it in to your context. However, why do you need to access it? I’m not going to say it’s a bad idea...it’s just a really bad idea