Passing Session to TWIG template

前端 未结 4 1999
春和景丽
春和景丽 2021-01-03 09:06

i have a problem when i want to get $_SESSION[\'session\']; in twig template using slim micro Framework.

this is my code :



        
4条回答
  •  半阙折子戏
    2021-01-03 09:46

    in php file:

    $app->get('/your_route_here', function() use ($app) {
    $app->render('view_for_route.twig', array('session_username' => $_SESSION['username']) );});
    

    in twig file:

    welcome {{ session_username }}

    You should pass the value from your PHP file into Twig via associative array.

提交回复
热议问题