简体   繁体   中英

How to call a php variable (not from a entity class) into a twig file

i want to call a php variable into a twig file.

suppose in my function i am getting "$usrname", so how can i return the value in the twig file ---

public function helloTestAction(){
    $usrname = $user->getUserDetails()->get()->getLatestName();
    // UserDetails is the entity class name
.........
} 

Suppose i get the answer "Hello Test", so now how can i return this value into my twig file.

So how can i get the "$usrname" in my twig file.

Anyone knows any solution for this problem. Thanks in advanced.

You can use as below :

return $this->render('AcmeDemoBundle:Welcome:index.html.twig', array(
            'usrname' => $usrname
    ));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM