Print a session variable through the twig engine

0

I entered a variable in the session named $_SESSION['ano'] . I would like to print your value on a page using twig.

I've tried:

{% for ano in app.session %}
    {{ ano }}
{% endfor %}  

But it does not work. How can I do it? The framework I'm working on is Slim.

    
asked by anonymous 23.01.2017 / 14:31

1 answer

1

I found the answer on this site:

  

link

In my case, just add the following:

$view->offsetSet("session", $_SESSION);  

And in the template: {{session.nomedavariavel}} .

I read elsewhere that it should be: $view->addGlobal("session", $_SESSION); , but it did not work in my case.

Update: Finally it is possible with the addGlobal method, inserting:

  

$ view-> getEnvironment () -> addGlobal ("session", $ _SESSION);

    
23.01.2017 / 15:47