twitter-bootstrap 使用 Bootstrap 自定义 FOSUserBundle 登录模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17127814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Custom FOSUserBundle Login Template using Bootstrap
提问by Daniel P
I've installed Symfony2, FOS User Bundle and Twitter Bootstrap.
我已经安装了 Symfony2、FOS User Bundle 和 Twitter Bootstrap。
Then I setup the /app/Resources/FOSUserBundle/views/layout.html.twig template to override FOSUserBundle to use my site template.
然后我设置 /app/Resources/FOSUserBundle/views/layout.html.twig 模板来覆盖 FOSUserBundle 以使用我的站点模板。
It all works if I have a link to /login on the homepage.
如果我在主页上有指向 /login 的链接,这一切都有效。
Now I want to implement a template like the hero templatewhere the login form is part of the main template.
现在我想实现一个像英雄模板这样的模板,其中登录表单是主模板的一部分。
The closest I've got is to use this in the main template:
我最接近的是在主模板中使用它:
{% render controller("FOSUserBundle:Security:login") %}
I can override the layout html to not extend main template, but this removes all styling from /login
我可以覆盖布局 html 以不扩展主模板,但这会从 /login 中删除所有样式
Any ideas how I can handle both scenarios?
有什么想法可以处理这两种情况吗?
采纳答案by Daniel P
Richard Miller's post has helped me achieve what I was trying to do.
理查德米勒的帖子帮助我实现了我想要做的事情。
http://richardmiller.co.uk/2013/02/18/symfony2-ajax-and-full-page-templates/
http://richardmiller.co.uk/2013/02/18/symfony2-ajax-and-full-page-templates/
{% extends app.request.attributes.get('partial')
? '::ajax-layout.html.twig'
: '::full-layout.html.twig' %}
I couldn't get app.request.partial to work, and decided choosing based on xmlRequest wasn't ideal.
我无法让 app.request.partial 工作,并决定基于 xmlRequest 进行选择并不理想。
回答by Nicolai Fr?hlich
You were almost there :)
你快到了:)
you can include the login form in any other template using the render function.
您可以使用渲染功能将登录表单包含在任何其他模板中。
{% render controller("FOSUserBundle:Security:login") %}
... you just have to create app/Resources/FOSUserBundle/views/Security/login.html.twigand ommit the wrapping {% block fos_user_content %}found in FOSUserBundle's login.html.twigin order to have it return the form directly:
...你只需要创建app/Resources/FOSUserBundle/views/Security/login.html.twig并省略{% block fos_user_content %}在 FOSUserBundle 的login.html.twig中找到的包装,以便让它直接返回表单:
{% if error %}
<div>{{ error|trans }}</div>
{% endif %}
<form action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
<label for="username">{{ 'security.login.username'|trans }}</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" />
<label for="password">{{ 'security.login.password'|trans }}</label>
<input type="password" id="password" name="_password" required="required" />
<input type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>
<input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
</form>
Then adjust it to fit your template.
然后调整它以适合您的模板。

