我已经为form_row创建了自己的主题并将其设置为在应用程序上全局使用,它看起来像这样:
fields.html.twig
{% block form_row %}
{% spaceless %}
{% set class="form-row" %}
{% if attr.class is defined %}
{% set class = class ~ ' ' ~ attr.class %}
{% endif %}
{% if not form.vars.valid %}
{% set class = class ~ ' error' %}
{% endif %}
<div class="{{ class }}" >
{% if (label is defined) and (label is same as(false)) %}
{{ form_widget(form) }}
{% else %}
{{ form_label(form) }}
{{ form_widget(form) }}
{% endif %}
{{ form_errors(form) }}
</div>
{% endspaceless %}
{% endblock form_row %}
然后我覆盖了FOSUserBundle注册表:
register_content.html
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_row(form.email, { 'attr': {'placeholder': 'form.placeholder.email'|trans}, 'label': false }) }}
{{ form_row(form.username, { 'attr': {'placeholder': 'form.placeholder.username'|trans}, 'label': false }) }}
{{ form_row(form.plainPassword.first, { 'attr': {'placeholder': 'form.placeholder.password'|trans}, 'label': false }) }}
{{ form_row(form.plainPassword.second, { 'attr': {'placeholder': 'form.placeholder.password_confirmation'|trans}, 'label': false }) }}
<div>
<ul class="no-bullet">
<li><input type="submit" value="{{ 'registration.submit'|trans }}" class="button radius expand" /></li>
<li><a href="#" class="facebook button radius expand">Sign Up with Facebook</a></li>
<li><a href="#" class="twitter button radius expand">Sign Up with Twitter</a></li>
</ul>
</div>
{{ form_end(form) }}
<p class="text-center">Already signed up? <a href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|trans({}, 'FOSUserBundle') }}</a></p>
</form>
我无法做的是将属性传递给form.plainPassword但只使用一次form_row()调用,这可能吗?
我正在寻找类似的东西:
{{ form_row(form.plainPassword, {
'first': { 'attr': {'placeholder': 'form.placeholder.password'|trans}, 'label': false },
'second': { 'attr': {'placeholder': 'form.placeholder.password_confirmation'|trans}, 'label': false }
})}}