简体   繁体   中英

Symfony 2: why form_theme not working for FOS_User registration template?

I have installed FOSUserBundle, customized template MyBundle::User:registration.html.twig with content

{% extends "::layout.html.twig" %}

{% form_theme form _self %}

{% block `form_widget_simple` %}
Hey! I wanna replace all your text fields in this form!
{% endblock %}

{% block content %}
   <h1>Registration</h1>
   {{form(form)}}
{% endblock content %}

My goal is to replace all text fields ( <input type="text"> ) in my form with contents of block form_widget_simple . Code above is not working: all fields are not replaced. But replacements is correct when I copy this code into another template (not related to FOSUserBundle). What is dark magic in the FOS User that prevents my replacements (or in my code)?

Did you follow the documentation ( https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md ) and correctly registered your bundle as a FOSUserBundle ?

Make sure to do the following modification, as written in the doc :

// src/Acme/UserBundle/AcmeUserBundle.php
<?php

namespace Acme\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeUserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM