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

本文是小编为大家收集整理的关于覆盖模板电子邮件FOSUserBundle的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

/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代码,因此我在文档中尝试了:

在{%bock body_html%}中添加所有HTML代码,使用或不带有"自动示例" - >相同结果...我可以看到所有HTML标签...

我做错了什么?

ex:

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

以及来自电子邮件/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>

推荐答案

好吧,最后我可以找到答案.

i正在重写重置controller,在services.yml中被宣布为我想使用的新控制器的依赖项注入,而不是从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', '']

本文地址:https://www.itbaoku.cn/post/2090849.html

问题描述

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

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

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'

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

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

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

What I'm doing wrong?

Ex:

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

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

And I get:

  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.

I tried also:

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

And I get:

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.

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.

So I got:

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

Replaced by:

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