Search code examples
symfonytwigblock

Override form_end block for one form


I want to override form_end block but only for one form. My blocks are loaded globally in my config.yml file. For example when i want to override form_row for one field i can make block like this -> formName.field.row.

I was trying to make something like this:

{% block formName_form_end %}
     my Code
{% endblock %}

but It doesn't work. Maybe it's just not possible to override form_end using form_name ? I mean that i can only override form_end, but in my case it will affect all forms.


Solution

  • You need form themeing.

    {% form_theme form _self %}
    
    {% block form_end %}
         my Code
    {% endblock %}
    
    {# Rest of template #}
    

    As noted in the documentation, use of _self tells Twig to look for block overrides within the current template file.