Creating sessions in Twig
Go to https://pluginfactory.io/ to generate a boilerplate Craft plugin.


API Version: Craft CMS version 2.5.x
PluginName: Twig Session
Description: Anything
Version: 1.0.0
Plugin Author: Anything
Author URL: Anything
Github Name: Blank
Uncheck: Tweet it out
Check: Variables
Click: Build Plugin


Download twigsession.zip and unzip it. Place the unzipped twigsession folder in your craft/plugins folder.  Open craft/plugins/twigsession/variables/TwigSessionVariable.php and change:

public function exampleVariable($optional = null)
{
    return "And away we go to the Twig template...";
}


To:

public function add($key, $value)
{
    craft()-&gt;httpSession-&gt;add($key, $value)
}


And add a new:

public function get($key)
{
    return craft()-&gt;httpSession-&gt;get($key)
}


Go to Settings->Plugins in the control panel. Install the "Twig Session" plugin.

From your front end templates, you can now use craft.twigSession.add('foo', 'bar') and craft.twigSession.get('foo').