https://symfony.com/doc/current/bundles/FOSUserBundle/emails.html
此链接显然解释了如何重写fosuserbundle中的电子邮件模板,以便为用户重置密码。
我得到了一个新的文件用于重新设置电子邮件(以前是
@FOSUser/Resetting/email.txt.twig
)现在抛出config.yml,我可以告诉fosuserbundle使用另一个文件。
fos_user:
service:
mailer: fos_user.mailer.twig_swift
resetting:
email:
template: 'email/password_resetting.email.twig'
在链接中说,如果我添加“mailer:fos-user.mailer.twig-swift”,就可以处理HTML代码。
这个新文件我需要添加一个HTML代码,所以我按照文档中的说明进行了尝试:
添加%块体HTML%中的所有HTML代码,无论是否有“自动转义”->相同的结果…我可以看到所有的HTML标记…
我做错什么了?
前任:
{# app/Resources/views/email/password_resetting.email.twig #}
{% block subject %}Resetting your password{% endblock %}
{% block body_text %}
{% autoescape false %}
Hello {{ user.username }} !
You can reset your password by accessing {{ confirmationUrl }}
Greetings,
the App team
{% endautoescape %}
{% endblock %}
{% block body_html %}
{#
//You can of course render the html directly here.
//Including a template as done here allows keeping things DRY by using
//the template inheritance in it
#}
<p><b>Test</b> test test</p>
{{ '<p><b>Test</b> test test</p>'|raw }}
{% include 'email/password_resetting.html.twig' %}
{% endblock %}
email/pasword_resetting.html.twig的内容是:
<p><b>Test</b> test test</p>
{{ '<p><b>Test</b> test test</p>'|raw }}
我得到:
Hello ricard !
You can reset your password by accessing https://blablabla.bla/app_dev.php/es/resetting/reset/MiPqznsUxHQLLgviDYtCsJrQZBiaqVzDU5ENvHcadA
Greetings,
the App team
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>
我想看到的是粗体和格式由段落句子而不是标签明显。
我也试过:
{# app/Resources/views/email/password_resetting.email.twig #}
{% block subject %}Resetting your password{% endblock %}
{% block body_text %}
{% autoescape false %}
Hello {{ user.username }} !
You can reset your password by accessing {{ confirmationUrl }}
Greetings,
the App team
{% endautoescape %}
{% endblock %}
{% block body_html %}
{#
//You can of course render the html directly here.
//Including a template as done here allows keeping things DRY by using
//the template inheritance in it
#}
{% autoescape 'html' %}
<p><b>Test</b> test test</p>
{{ '<p><b>Test</b> test test</p>'|raw }}
{% endautoescape %}
{% autoescape %}
<p><b>Test</b> test test</p>
{{ '<p><b>Test</b> test test</p>'|raw }}
{% endautoescape %}
<p><b>Test</b> test test</p>
{{ '<p><b>Test</b> test test</p>'|raw }}
{% endblock %}
我得到:
Hello ricard !
You can reset your password by accessing https://blablabla.bla/app_dev.php/es/resetting/reset/2G2ZGW262Z1THu1_80k2vAQMdI4-faNFVFWgdOVts8
Greetings,
the App team
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>
<p><b>Test</b> test test</p>