Hello,
Reference: #878 (is closed!?)
Problem is:
An exception has been thrown during the rendering of a template
("Some mandatory parameters are missing ("token") to generate
a URL for route "fos_user_resetting_reset".") in
FOSUserBundle:Resetting:reset.html.twig at line 4.
The templates be total normal ...
Information: I could override ALL templates except the one with the "token" parameter.
And second information: I could override the templates "normal" without "extends" or "include" tags... Then everythink is okay. But if i use extends or include tag i get the error =.=
FOSUserBundle:Resetting:reset.html.twig
{% extends "FOSUserBundle::layout.html.twig" %}
{% block fos_user_content %}
{% include "FOSUserBundle:Resetting:reset_content.html.twig" %}
{% endblock fos_user_content %}
FOSUserBundle:Resetting:reset_content.html.twig
{% extends "FOSUserBundle::layout.html.twig" %}
{% block contentmain %}
<form action="{{ path('fos_user_resetting_reset', {'token': token|default('123abc')}) }}" {{ form_enctype(form) }} method="POST">
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'resetting.reset.submit'|trans }}" />
</div>
</form>
{% endblock %}
FOSUserBundle::layout.html.twig
{% extends '::base.html.twig' %}
{% block contentmain %}
{% block fos_user_content %}{% endblock %}
{% endblock %}
Dont know why there is a problem with this... Only one parameter in route...
I had the same problem .
Provisionally fixed this with an iframe ...
reset_content.html.twig should not extend the layout as it is included in the other file extending the layout.
Why i'm so stupid in this terms?? -.-
Thank you @stof :+1:
You should made an FAQ for things like this ^^
Why you get an template error?
A: If your template name contains a "_content" you cant use "extends" or "include".
...
Thx
@stof Other example:
I renamed my "reset.html.twig" file into "aaareset.html.twig".
And my "reset_content.html.twig" file into "aaareset_content.html.twig".
Same error...
Dont know why. Is there a event which destroys the function?
[2/2] Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("token") to generate a URL for route "fos_user_resetting_reset".") in "FOSUserBundle:Resetting:reset.html.twig". -
Dont know ...
Okay solution and "HOW TO DEBUG THIS SHIT?"
Step 1.)
Open the error file which throws the exception.
CRITICAL - Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the
rendering of a template ("Some mandatory parameters are missing ("token") to generate a URL for route
"fos_user_resetting_reset".") in "FOSUserBundle:Resetting:reset.html.twig"." at /var/www/app/cache/dev/classes.php line 4355
Step 2.)
Comment the lines out! (//)
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e);
>>>>>>
//throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e);
Step 3.)
Reload the page.
Look into source code with the browser. (mostly STRG + U / Firefox/Chrome)
Step 4.)
Look at the end of the page. The page source should be closed unnormally...
Example:
<a href="...">Imprint</a> - <a class="contactlink" href="
Step 5.)
Be happy and look into the template (example ::base.html.twig) and look what you use at the position above.
My problem was the base.html.twig:
<a href="http://twitter.com/home?status={{ url(app.request.attributes.get('_route')) | url_encode }}"
target="_blank" title="Twitter">Twitter</a>
...
The parameters failed ^^
Use another link instead on "secret" pages.
If you include the files in the
{% block fos_user_content %} {% endblock fos_user_content %}
block, it seems to work. (well, at least sometimes if it is without any routing).
got problem too with this
i try to overide the reset template like this
request.html.twig
{% extends '::base.html.twig' %}
{% block fos_user_content %}
{% include "FOSUserBundle:Resetting:request_content.html.twig" %}
{% endblock fos_user_content %}
but when i come to th page /resetting/reset/thetoken
i got an error
Some mandatory parameters are missing ("token") to generate a URL for route "fos_user_resetting_reset"
don't know how to override the template without errors
I want my template, not the blank page with the 2 fields, need it in my website template
This is because in the first one you extend an existing template, a child template may only define blocks.
Existing blocks in the parent will then be overwritten with that of the child's.
Meaning that the parent will only render blocks that exist in the parent, if you define a block in the child that does not exist in the parent the parent will render it.
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md
ok
so, how can i have the reset form in my website with my look and feel ?
How do you do guys to do this ?
Do i copy/paste the whole base html twig to get the same result and include the form in it ? (seem bad and dirty)
temp solution:
//public function resetAction($token)
public function resetAction() //temp solution
{
$token = $_GET['token']; //temp solution
....
....
fos_user_resetting_reset:
pattern: /senha/reset
defaults: { _controller: FOSUserBundle:Resetting:reset }
#methods: [GET] #temp solution
@ibasaw you can overwrite the template. The only thing is that your overwritten template must generate the route properly (i.e. passing the mandatory parameters) instead of just generating the route name without parameters.
Guys it acting wired. When your base.html.twig is screwed up it shows that error. Just recheck all includes in base file.
ok, it's good now. thank to @stof and @emgiezet
got a bad path in my base.html.twig
@ibasaw I'm glad that it helped!
I still had the same issue. Looks like a small issue in the MailerMailer
public function sendResettingEmailMessage(UserInterface $user)
{
$template = $this->parameters['resetting.template'];
$url = $this->router->generate('fos_user_resetting_reset', array('token' => $user->getConfirmationToken()), true);
$rendered = $this->templating->render($template, array(
'user' => $user,
'confirmationUrl' => $url
));
$this->sendEmailMessage($rendered, $this->parameters['from_email']['resetting'], $user->getEmail());
}
token is not passed to template
$rendered = $this->templating->render($template, array(
Only user and confirmationUrl
try This
{% trans_default_domain 'FOSUserBundle' %}
<form id="form-reset-pwd" action="{{ path('fos_user_resetting_reset', {'token': token}) }}" {{ form_enctype(form) }} method="POST" class="fos_user_resetting_reset">
<div class="form-group form-group-default">
<div class="controls">
<div id="fos_user_resetting_form">
<div>
<input type="password" id="fos_user_resetting_form_plainPassword_first" class="form-control" name="fos_user_resetting_form[plainPassword][first]" placeholder="New password" required="required" aria-required="true">
</div>
</div>
</div>
</div>
<div class="form-group form-group-default">
<div class="controls">
<div id="fos_user_resetting_form">
<div>
<input type="password" id="fos_user_resetting_form_plainPassword_second" class="form-control" name="fos_user_resetting_form[plainPassword][second]" placeholder="Repeat new password" required="required" aria-required="true">
</div>
</div>
</div>
</div>
<button id="validate-login" type="submit" value="{{ 'resetting.reset.submit'|trans }}" class="btn btn-orange btn-cons btn-animated from-left fa fa-arrow-right action submit" style="display: block;">
<span>{{ 'resetting.reset.submit'|trans }}</span>
</button>
{{ form_row(form._token) }}
</form>
For other sufering this behaviour (and arrive here from google) when extend templates over the resetting template (for example for modify the layout) with twig variables that contains "_", in my case it was "_route" (via app.request.attributes.get('_route')) like this:
{% set current_path_name = app.request.attributes.get('_route')|url_encode|default('myapp_index') %}
{% set current_path = path(current_path_name) %}
My workaround was set always by default a value for the "token" which was complaning, passing a default value since it is not picking the right one for the extends.
{% set current_path_name = app.request.attributes.get('_route')|url_encode|default('myapp_index') %}
{% set current_path = path(current_path_name, {token : token|default('1234') }) %}
In my opinion, I don't understand why we cannot use _variables in extends, it should be supported or fosuser bundle should change the approach for allow easy extends in his templates, because probably a lot people has this bug at some point in customization
Using Symfony 4, in my case the issue was that in the database, User table, the field confirmation_token was empty string '' and it should be NULL. It worked for me with NULL value.
It was empty string because I forgot it so during several debugging moments.
Most helpful comment
try This