Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how create session as global var in volt

Hi guys.

tell me please, how create session as global var in volt for use at:

{{ sess.user.first_name }}

when session equal:

array (
    'user' => array ( 
        'first_name' => 'John', 
        'last_name' => 'Doe'

because it not work:

$view->setVar('sess', (object)$_SESSION);

and it too

$view->setVar('sess', $this->getDI()->getShared('session'));

:) Hi there... u can use all shared services in volt. For example:

If u have $this->session->set("some", "hi there");

// In volt
{{ session.some }}

However, it is good idea to check...

{% if session.has("some") %}
{% endif %}

So u didnt need to put global var like this :) One tip- like i said - all services are valid in volt too, so u can use request, response, etc:

{% if response.hasQuery("name") %}
{% endif %}

Good luck

hmm, thanks Boris!

and how use at:


if some is array? session.some['x'] - no good, not comfortable.

edited Oct '15

Use object then: Its good idea to create stdClass:

$obj = new stdClass(); 
$obj->first_name = 'Hii';
$this->session->set('obj', $obj);

so in volt: {{ session.obj.first_name }} When obj is type array, then : {{ session.obj["first_name"] }}

U can deside what is best for u :D good luck