I am customizing the confirmation email sent after user registration.
My problem is that I can’t access session vars in the email template.
Here is my code (similar to FOSUser documentation) :
{# src/Acme/DemoBundle/Resources/views/User/confirmation.email.twig #}
{% block subject %}Confirmation{% endblock %}
{% block body_text %}
{% autoescape false %}
Hello {{ user.username }} !
Your locale is : {{ app.session.locale }}
Click on the following link to confirm your registration : {{ confirmationUrl }}
Greetings,
the Acme team
{% endautoescape %}
{% endblock %}
{% block body_html %}
{% include 'AcmeDemoBundle:User:confirmation_email.html.twig' %}
{% endblock %}
The following line returns an exception :
Your locale is : {{ app.session.locale }}
Exception :
Variable "app" does not exist in ...
How can I access session var from this template ?
I also need to access config parameters (from parameters.ini).
My parameters are already in global Twig access, but no way to access them in this template.
Many thanks for your help !
A
TwigSwiftMailer class only expose
Userentity and confirmation url to the template. You have to extend the class and modify the methods. Then create the service and set as default mailer. You can check here for service definition.Edit:
Sample implementation would be
The class .
Service declaration. Create a class named
mailer.xmlin your bundlesResources/configfolder.To include the
loader.xmlyou have to include following lines inloadmethod ofYourBundle/DependencyInjection/YourBundleExtension.phpAnd in
app/config.ymlset the mailer.Now in your template you can do
{{ session.get('var') }}or{{ container.getParameter('any_param') }}