I'm trying to understand the FOSUserBundle implementation of Twig and a relative novice with Symfony2. I'd like to override the default implementation and send html emails using the fos_user.mailer.twig_swift mailer service.
My environment: Symfony 2.4.1
"require": {...
"symfony/swiftmailer-bundle": "~2.3",
"friendsofsymfony/user-bundle": "*"
Here's where I'm stuck: based on the FOSUserBundle documentation (here). The line that kills me is:
{% include 'AcmeDemoBundle:User:resetting_email.html.twig' %}
Following their instructions I get:
" Unable to find template "PP2UserBundle:User:resetting_email.html.twig" - (PP2UserBundle is my implementation of AcmeDemoBundle)
And that error almost makes sense to me. I don't understand where it would find that template. So to keep it from crashing, I delete the include and add some html code to test if it sees my template and sends the email. It does and I get a nice email with "Hi" in the {% block body_html %}. The {% block subject %} also renders. But the {% block body_text %} is empty. Oof.
Here's my code. If anyone could share some insight, I'd really appreciate it!
Service is Registered and looks OK. (Though I have my doubts about the yml implementation) I picked the up xml->yml translation off another post.
services.yml
fos_user.mailer.twig_swift:
class: FOS\UserBundle\Mailer\TwigSwiftMailer
arguments:
- @mailer
- @router
- @twig'
- { template: { confirmation: %fos_user.registration.confirmation.template%, resetting: %fos_user.resetting.email.template% }, from_email: { confirmation: %fos_user.registration.confirmation.from_email%, resetting: %fos_user.resetting.email.from_email% } }
Config.yml looks logical.
service:
mailer: fos_user.mailer.twig_swift
resetting:
email:
template: PP2UserBundle:User:resetting.email.twig
And my template placed in Resources/views/User
resetting.email.twig
{% block subject %} Test Resetting your password{% endblock %}
{% block body_text %}
{% autoescape false %}
Hello {{ user.username }} !
You can reset your email by accessing {{ confirmationUrl }}
Greetings,
the Acme team
{% endautoescape %}
{% endblock %}
{% block body_html %}
<h1> hi </h1>
{% include 'PP2UserBundle:User:resetting_email.html.twig' %}
{% endblock %}
Again if I take out {% include 'PP2UserBundle:User:resetting_email.html.twig' %} I get a nice little 'hi' but little else.
It feels like I should be extending the fosuser templates in views/Resetting, (or including them) but I don't see which. I'm missing something.
Thanks again.
PP2UserBundle:User:resetting.email.html.twigmeans the template should be inYourBundleFolder/Resources/views/User/resetting.email.html.twig- JamesHalsall