Sending Error Message to Template With No Logged In User - Craft 2
You are mixing Craft 3 code with Craft 2. There is no native way to access the session in Craft 2 via Twig so you need to inject the functions with your plugin

See a working example here