I've got a view where I'm trying to override the form theme for an individual field per http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field.
The view looks something like this:
{% form_theme form _self %}
{% block _my_form_foo_widget %}
<div class="input-append">
{{ block('number_widget') }}
<span class="add-on">%</span>
</div>
{% endblock %}
<form>
{{ form_row(form.foo) }}
{{ form_row(form.bar) }}
</form>
Everything looks as expected for the foo and bar rows, however, the _my_form_foo_widget block itself is also included in the output, i.e.:
<div class="input-append">
<span class="add-on">%</span>
</div>
<form>
<div>
<label for="my_form_foo">Bar</label>
<div class="input-append">
<input type="text" id="my_form_foo" name="my_form[foo]">
<span class="add-on">%</span>
</div>
</div>
<div>
<label for="my_form_bar">Foo</label>
<input type="text" id="my_form_bar" name="my_form[bar]">
</div>
</form>
I can't for the life of my figure out what I'm doing wrong. As a workaround I just wrapped the block in HTML comments.
I'm on Symfony 2.4.1 and Twig 1.15.0.
%sign. Have you tried changing the%in the<span>to a different character (i.e.+) yet? If that works you could try replacing the%with{{ '%' }}. Further you could try to move the overriding block to a distinct template (i.e.form_theme.html.twig) and use{% form_theme form 'form_theme.html.twig' %}- Nicolai Fröhlich%to something else makes no difference. - enoshixi