覆盖模板电子邮件FOSUserBundle [英] Override template email FOSUserBundle

查看:122
本文介绍了覆盖模板电子邮件FOSUserBundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://symfony.com/doc/current/bundles/FOSUserBundle /emails.html

此链接显然说明了如何覆盖FOSUserBundle中的电子邮件模板以重置用户密码.

This link explains apparently how to override the email template from FOSUserBundle for resetting password for a user.

我有一个用于重置电子邮件的新文件(之前是@FOSUser/Resetting/email.txt.twig),现在抛出了config.yml,我可以告诉FOSUserBundle使用另一个文件.

I got a new file for the Resetting email (before was @FOSUser/Resetting/email.txt.twig) and now throw the config.yml I can tell FOSUserBundle to use another file.

fos_user:
    service:
        mailer: fos_user.mailer.twig_swift
    resetting:
        email:
            template:   'email/password_resetting.email.twig'

在链接中说,如果我添加"mailer:fos_user.mailer.twig_swift",则可以处理html代码.

In the link says that if I add "mailer: fos_user.mailer.twig_swift" will be possible to handle html code.

这个新文件我需要添加HTML代码,因此我按文档中的说明进行了尝试:

This new file I need to add a HTML code, so I tried as it says in the documentation:

在{%block body_html%}内添加所有html代码(带有或不带有自动转义")->相同的结果...我可以看到所有的html标签...

Adding all the html code inside {% block body_html %} with or without "autoescape" -> same result... i can see all the html tags...

我做错了什么?

例如:

{# 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中的内容是:

And the content from email/pasword_resetting.html.twig is:

<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>

我希望看到的是粗体和按段落句子格式化的标签,而不是明显的标签.

I would like to see the bold and formated by paragraph sentence not the tags obviously.

我也尝试过:

{# 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>

推荐答案

好,终于可以找到答案了.

Oks, finally I could find the answer.

我正在重写ResettingController,并在services.yml中声明了对该新控制器的依赖项注入,而不是FOSUserBundle中的默认控制器.

I was rewriting the ResettingController and in the services.yml was declared the dependency injection to this new Controller I wanted to use instead of the default controller from FOSUserBundle.

所以我得到了

AppBundle\Controller\ResettingController:
    class: AppBundle\Controller\ResettingController
    arguments: ['','@fos_user.resetting.form.factory', '','','@fos_user.mailer.default', '']

替换为:

AppBundle\Controller\ResettingController:
    class: AppBundle\Controller\ResettingController
    arguments: ['','@fos_user.resetting.form.factory', '','','@fos_user.mailer.twig_swift', '']

这篇关于覆盖模板电子邮件FOSUserBundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆