yahyaharif
yahyaharif

Reputation: 170

ContextErrorException and Twig syntax error issue with a twig template - Symfony (FOSUserBundle)

I am using FOSUserBundle on Symfony for my user registration. I followed the required steps and proceeded to override the templates as indicated.

I was met with these errors:

ContextErrorException: Notice: Undefined variable: test

Followed by:

Twig_Error_Syntax: An exception has been thrown during the compilation of a template ("Notice: Undefined variable: test") in "FOSUserBundle:Registration:register_content.html.twig"

Here is the register_content.html.twig in question:

{% trans_default_domain 'FOSUserBundle' %}

<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} 
      method="POST" 
      class="fos_user_registration_register">
    {{ form_widget(form) }}
    <div>
        <input type="submit" value="{{ 'registration.submit'|trans }}" />
    </div>
</form>

RegistrationType:

<?php


namespace DEA\CourriersBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('nom')
            ->add('prenom')
            ->add('fonction')
            ->add('telephone');
    }

    public function getParent()
    {
        return 'fos_user_registration';
    }

    public function getName()
    {
        return 'app_user_registration';
    }
}

I did not override the controller. You can find it here.

I can't even locate the said "test" variable. Any help is appreciated, I've been struggling with this for a whole day.

Upvotes: 2

Views: 1169

Answers (3)

FERRASSI Badr
FERRASSI Badr

Reputation: 94

The form_enctype(form) was deprecated in Symfony 2.3 and will be removed in Symfony 3.0. You should use form_start() instead.

Upvotes: 0

Christophe Coevoet
Christophe Coevoet

Reputation: 1009

The solution is to update Twig to the latest version.

The error happens because of a bug in Twig, which has been fixed in Twig 1.21.2: https://github.com/twigphp/Twig/pull/1801

Upvotes: 2

yahyaharif
yahyaharif

Reputation: 170

I found a solution even though I don't understand why it worked.

I removed the

{{ form_enctype(form) }}`

As it was for some reason causing the error. Maybe my file encoding had something to do with it?

Upvotes: 0

Related Questions