Search code examples
phpsymfonytwigtwig-extension

Symfony Form form_rest block not recognized


I am using FosUserBundle for an application. I am overriding the registration template inside (app/Resources/FOSUserbundle/views/Registration/register.html.twig).

register.html.twig

{% extends 'base.html.twig' %}
{% form_theme form '@FOSUser/Form/register_theme.html.twig' %}

{% block body %}
...
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
...
{{ form_rest(form) }} 
//this is just for testing since form_end contains form_rest 
//inside of it if you have a look at form_div_layout.html.twig.

{{ form_end(form) }}
...
{% endblock body %}

and contains a form_theme file where I changed 2 blocks (which are not related to this question)

register_theme.html.twig

{% extends "form_div_layout.html.twig" %}

{% block form_widget_simple %}
//some code here
{% endblock form_widget_simple %}

The problem is that all worked fine until 2.8 update (I still don't think it has to do with this but maybe I don't see something).

So when I try to use the form_rest i get the following error:

An exception has been thrown during the rendering of a template ("Unable to render the form as none of the following blocks exist: "_fos_user_registration_form_rest", "fos_user_registration_rest", "fos_user_registration_rest", "form_rest".") in FOSUserBundle:Registration:register.html.twig at line xx

If i do not use form_rest the csrf token is missing and i cannot complete the registration. If I use only form_end will still generate the error because form_rest is contained inside of it.


Solution

  • I'm supposing you have a custom Form to add your own fields. I was having the same issue and found out that the way to extend fosuserbundle's registration form has changed in sf 2.8. Check out the documentation:

    http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html