4

Is there a way to get the session id from craft.session in a twig template without needing to create a new filter?

2 Answers 2

3

Old post, I know, but we've recently published a plugin to achieve this for a similar problem we were facing.

SessionExposer plugin can help you achieve this. To get the Session ID in the template you use

{{ craft.sessionExposer.sessionId }}
4
  • Any idea if this plugin is still available somewhere? Need to do this on a legacy Craft2 site. Commented Nov 29, 2022 at 17:06
  • @erwinheiser yes I've restored it at github.com/madebymutual/SessionExposer now, please note it's archived and entirelty unsupported. But hopefully it works for you
    – Mutual
    Commented Nov 30, 2022 at 8:05
  • That's awesome, many many thanks! I'll definitely check it out. Commented Dec 1, 2022 at 10:05
  • works as advertised, thanks again! Commented Dec 1, 2022 at 17:56
1

I assume you're referring to the PHP session ID (wrapped by HttpSessionService)?

If so, the answer is no - Craft doesn't expose that to the templates. You'd have to write a plugin that did.

1
  • Yes, I has hoping to grab the session to send along for a unique identifier for some tracking purposes. Looked at the request.getCookie() also but no luck. Commented May 28, 2015 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.