risolto questo problema utilizzando il seguente codice nella mia forma-tema:
{# ---- form-theme.html.twig #}
{% block checkbox_row %}
{% spaceless %}
<div>
{{ form_errors(form) }}
<label class="checkbox" for="{{ form.vars.id }}">
{{ form_widget(form) }}
{{ label|default(form_label(form)) | raw }}
</label>
</div>
{% endspaceless %}
{% endblock %}
nel modulo-Template è possibile utilizzare:
{% form_theme form '::form-theme.html.twig' %}
{{form_row(form.termsOfServiceAccepted, {
'label' : 'I have read and agree to the <a href="#">Terms and conditions</a>'
})
}}
in questo modo, il blocco dal form- il tema si applica a qualsiasi checkbox sulla pagina. Se si deve usare anche il default-tema, è possibile aggiungere un parametro per consentire speciale rendering:
{# ---- form-theme.html.twig #}
{% block checkbox_row %}
{% spaceless %}
{% if not useTosStyle %}
{{ parent() }}
{% else %}
{# ... special rendering ... #}
{% endif %}
{% endspaceless %}
{% endblock %}
che sarebbe utilizzato come questo:
{% form_theme form '::form-theme.html.twig' %}
{{form_row(form.termsOfServiceAccepted, {
'useTosStyle' : true,
'label' : 'I have read and agree to the <a href="#">Terms and conditions</a>'
})
}}
fonte
2012-03-06 12:25:49
Qual è il tuo problema esattamente? –