问题
I did some research and sadly couldn't find any help for that.
So I'm rendering the FOSUserBundle ChangePasswordAction into a template of mine, but it displays the default template given from the vendor.
My template where the controller is rendered:
{% block body %}
<h2>Einstellungen</h2>
<br/>
<h4>Ändern Sie ihr Passwort</h4>
{% render controller("FOSUserBundle:ChangePassword:changePassword") %}
{% endblock %}
My template for the ChangePasswordAction, the path is app/Resources/FOSUserBundle/views/ChangePassword/changePassword.html.twig
:
{% block fos_user_content %}
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_change_password') }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
{{ form_start(form) }}
{{ form_errors(form) }}
<p><span class="edit_left_date">{{ form_label(form.current_password, 'Jetziges Passwort') }} </span>
<span class="edit_right">{{ form_widget(form.current_password) }}</span></p>
<p><span class="edit_left_date">{{ form_label(form.new_password, 'Neues Passwort') }} </span>
<span class="edit_right">{{ form_widget(form.new_password) }}</span></p>
<p><span class="edit_left_date">{{ form_label(form.new_password_confirmation 'Bestätigen Sie ihr neues Passwort') }} </span>
<span class="edit_right">{{ form_widget(form.new_password_confirmation) }}</span></p>
<div>
<input type="submit" value="{{ 'Speichern'|trans }}" />
</div>
{{ form_end(form) }}
</form>
{% endblock %}
What drives me crazy is that i render the login controller from the FOSUserBundle the same way in my layout.html.twig and it's working perfectly there.
The snippet of code from the layout:
{% block sidebar %}
{% render controller("FOSUserBundle:Security:Login") %}
{% endblock %}
and the app/Resources/FOSUserBundle/views/Security/login.html.twig
:
{% block fos_user_content %}
<div class="teaser-header">Login</div>
<form role="form" action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
<div class="form-group">
<label for="username">{{ 'MyLog Username'|trans }}</label>
<input class="form-control" type="text" id="username" name="_username" placeholder="Your Username" required="required" />
</div>
<div class="form-group">
<label for="password">{{ 'Password'|trans }}</label>
<input class="form-control" type="password" id="password" name="_password" placeholder="Your Password" required="required" />
</div>
<input type="submit" id="_submit" name="_submit" value="{{ 'Segel setzen'|trans }}" />
<a id="passwordForget" href={{ path('fos_user_resetting_request') }}>Password vergessen?</a>
</form>
{% endblock %}
Am i missing something or what am i doing wrong so i can't override the changePassword
Template?
回答1:
Moving from comments to an answer:
Have you cleared your cache since adding the new template?
回答2:
What you basically do is you create a user bundle of your own + set it's parent to the FOS user bundle. (You should already have done this step)
Then you set the template in:
MyCompany/MyProject/UserBundle/Resources/views/Resetting/request.html.twig
Because of the fact that the file in the FOS user bundle is on the same place, your file will overwrite that template.
回答3:
If you think you've done everything correctly and still it doesn't work, you can try to clear the cache with a Symfony command in the terminal, or in some cases manually delete the cache directories - 'app/cache/dev' or 'app/cache/prod'.
来源:https://stackoverflow.com/questions/24386601/overriding-change-password-template-from-fos-user-bundle