FOSUserBundle:覆盖Twig模板:添加HTML元素 [英] FOSUserBundle : Overriding a Twig template : adding HTML elements
问题描述
我正在使用 FOSUserBundle ,我想在注册表单中添加一些HTML元素.实际上,我做到了,并且可以在表单中看到添加到User类的属性.问题是我希望这些字段(名字,姓氏,出生日期等)能够获得CSS模板(引导程序)的外观. 由于已显式声明了HTML,因此我通过覆盖登录页面成功完成了此操作.我想对注册页面执行相同的操作,但是对我来说似乎很困惑,因为这是:
I'm using FOSUserBundle, and I want to add a few HTML elements to the registration form. Actually, I did and I can see the added properties to the User class in my form. The issue is that I want those fields (first name, last name, date of birth, etc..) to get the look and feel of my CSS template (bootstrap). I succeeded to do that for the login page by overriding it, since the HTML are explicitly declared. I want to do the same for the register page, however it seems confused to me, because here's the content of :
-
register.html.twig
{%扩展了"FOSUserBundle :: layout.html.twig"%}
{% extends "FOSUserBundle::layout.html.twig" %}
{%block fos_user_content%} {%包括"FOSUserBundle:Registration:register_content.html.twig"%} {%endblock fos_user_content%}
{% block fos_user_content %} {% include "FOSUserBundle:Registration:register_content.html.twig" %} {% endblock fos_user_content %}
register_content.html.twig
{%trans_default_domain'FOSUserBundle'%}
{% trans_default_domain 'FOSUserBundle' %}
如何从此代码访问页面中看到的元素?
How can I access to the elements that I see in the page from this code ?
推荐答案
尝试一下
<div class="form-group {% if form.plainPassword.first.vars.errors %}has-error{% endif %}">
<label class="col-lg-2 control-label">Password:</label>
<div class="col-lg-5">
{{ form_widget(form.plainPassword.first, {'attr': {'class': 'form-control input-lg', 'placeholder': 'Enter password', 'required': 'required'}}) }}
{% for errorItem in form.plainPassword.first.vars.errors %}
<label class="control-label has-error" for="{{ form.plainPassword.vars.id }}">{{ errorItem.message }}</label>
{% endfor %}
</div>
<div class="col-lg-5">
{{ form_widget(form.plainPassword.second, {'attr': {'class': 'form-control input-lg', 'placeholder': 'Enter password again', 'required': 'required'}}) }}
</div>
</div>
对我有用.
这篇关于FOSUserBundle:覆盖Twig模板:添加HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!