简体   繁体   English

如何在树枝文件中调用php变量(不是来自实体类)

[英]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. 我想将php变量调用到树枝文件中。

suppose in my function i am getting "$usrname", so how can i return the value in the twig file --- 假设在我的函数中我得到“ $ usrname”,那么如何在树枝文件中返回值-

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. 假设我得到了“ Hello Test”的答案,那么现在如何将这个值返回到我的树枝文件中。

So how can i get the "$usrname" in my twig file. 因此,如何在我的树枝文件中获取“ $ usrname”。

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
    ));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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