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
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 }}
-
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– MutualCommented 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
-
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.
-
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