0

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?

3
  • 1
    Not possible, as render returns the resulting html response. Commented Jan 18, 2014 at 15:30
  • Mumm, I explain: I want to display error message in the main div, by i don't find the way to get error message in my layout twig?? Commented Jan 18, 2014 at 15:32
  • is there any other way to include FSOUserBundle:Security:login in my main layout? by the way sorry for my bad english :p Commented Jan 18, 2014 at 15:35

1 Answer 1

2

What you are trying to do is not intended by the symfony developers.

render() should render exactly one template if possible. 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. You inject all variables when rendering the child template in the controller ($this -> render('templateName',array()))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.