我已经安装了 Symfony2、FOS User Bundle 和 Twitter Bootstrap。
然后我设置/app/Resources/FOSUserBundle/views/layout.html.twig 模板覆盖 FOSUserBundle 以使用我的站点模板。
如果我在主页上有指向/login 的链接,这一切都有效。
现在我想实现一个模板,如 hero template其中登录表单是主模板的一部分。
我最接近的是在主模板中使用它:
{% render controller("FOSUserBundle:Security:login") %}
我可以覆盖布局 html 以不扩展主模板,但这会从/login 中删除所有样式
有什么想法可以处理这两种情况吗?
最佳答案
你快到了:)
您可以使用渲染功能将登录表单包含在任何其他模板中。
{% render controller("FOSUserBundle:Security:login") %}
...您只需创建应用程序/资源/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>
然后调整它以适合您的模板。
关于symfony - 使用 Bootstrap 自定义 FOSUserBundle 登录模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17127814/