简体   繁体   English

symfony2 {%render(controller())%}

[英]symfony2 {% render (controller()) %}

In my main layout, i render another controller like this: 在我的主要布局中,我渲染另一个控制器,如下所示:

{# main layout.html.twig #}
<div id="login">
    {% render(controller("FOSUserBundle:Security:login")) %}
</div>

<div id="main">

</div>

this controller generate differents variables (lastUserName, csrf_token, error), Now how can i use these variables in my main layout.html.twig? 这个控制器生成不同的变量(lastUserName,csrf_token,error),现在我如何在我的主layout.html.twig中使用这些变量?

What you are trying to do is not intended by the symfony developers. 你想要做的是symfony开发人员不打算做的。

render() should render exactly one template if possible. 如果可能,render()应该只渲染一个模板。 This template should extend other templates. 此模板应扩展其他模板。 So what you can do is: 所以你能做的是:

// FOSUserBundle:Security:login (Template)
{% extends main_layout.html.twig %}

{{ someVariable }}
{% block someName %}  
    YOUR DESIGN
{% endblock %}

// FOSUserBundle:Security:login (Template)    
SOME DESIGN
{{ someVariable }}
{% block someName %}  
    empty
{% endblock %}
SOME DESIGN

The variable someVariable is useable in main_layout and in the login template. 变量some​​Variable可用于main_layout和登录模板。 You inject all variables when rendering the child template in the controller ($this -> render('templateName',array())) 在控制器中渲染子模板时注入所有变量($ this - > render('templateName',array()))

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

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