symfony/symfony — Issue #3380: Can't redefine a block of a custom form theme
Author: egeloen
Created: 2012-02-16 15:04:33+00:00
State: open

Hello,

## Context

I've a custom form theme, let's call it `custom_theme.html.twig`, inherited form the twig default one [form_table_layout.html.twig](https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig).

**This custom form theme is not the default for the entiere sf2 application.**

On a twig template, I declare the use of this form theme

``` twig
{# Twig template of an action #}

{% form_theme form 'MyBundle:Form:form_registration_layout.html.twig' %}
```

This form theme is widely used within my app, and works well for all the form it is applied to. However, for **one special form**, I'd like to redefine one of its block - the way it displays a `choice` widget.

## Problem

I thought it would be possible to declare this block within the template where the `{% form_theme form (...) %}` is called :

``` twig
{# Twig template of an action #}

{% form_theme form 'MyBundle:Form:form_registration_layout.html.twig' %}

{% block choice_widget %}
{% spaceless %}

{% for children in form %}

{{ form_widget(children) }}
{{ form_label(children) }}

{% endfor %}

{% endspaceless %}
{% endblock choice_widget %}
```

However this new block is never called. Instead, the `choice_widget` block from my custom theme is called.

## Request

Being able to redefine blocks on the fly would be really useful.
I know it's possible to workaround by creating another theme, which inherit my ` custom_theme.html.twig`, but it feels wrong to do so, as it would be only ever used once in the whole app.

Also, redefining blocks on the fly is already possible, as seen [in the doc](http://symfony.com/doc/current/book/forms.html#twig) however this is only possible if the theme you're using is the default one, set in the configuration, not if you previously defined one using `{% form_theme form (...) %}`