i want to insert the login form of FOSUserBundle in my template like this:
<div id="sidebar">
{% render "FOSUserBundle::Security::login" %}
</div>
but not to render the template that is been calling in the code of loginAction() originally.
I have thought I'd find useful the possibility of passing the template I want to render as a parameter as 'max' in this example:
<div id="sidebar">
{% render "AcmeArticleBundle:Article:recentArticles" with {'max':
3} %}
</div>
Is that possible in symfony2? If not..
should I create another action for my bundle with the same code inside of loginAction? or should I modify the original loginAction code and write control structures?
if(currentPage == 'home')
renderResponse('template1')
else
renderResponse('template2')
You can create a partial to store your plain HTML form, for example this simple one:
<form action="{{ path("fos_user_security_check") }}" method="post">
<label>Email</label>
<input type="text" name="_username" required="required" />
<label>Password</label>
<input type="password" name="_password" required="required" />
<button type="submit">Submit</button>
</form>
Then in your layout just include your brand new partial :)
If you need the csrf token (which is highly recommended), just define the provider as a Twig global variable:
twig:
globals:
fos_csrf_provider: "@form.csrf_provider"
Then just add the hidden input field in your form:
<input type="hidden" name="_csrf_token" value="{{ fos_csrf_provider.generateCsrfToken('authenticate') }}" />
You have to specify that you are calling a controller
{{ render(controller('FOSUserBundle:Security:login')) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With