Extends a template that does not work with FOSUserBundle emails. Symfony2

I have a problem with letters and template extension. I try to create one template for emails, and then in different Bundles use one template for emails. I have my own package, which I have successfully achieved this, but problems arise when I try to expand FosUserBundle: reset email.

My app template / Resources / views / email_base.html.twig

{% block subject %}{% endblock subject %}

<div dir="ltr" style="display: block; width: 100%; background: #ffffff">
    <div class="gmail_quote">
        <div style="margin:0;padding:20px 0; background: #ffffff">
            <table align="center" bgcolor="#F9F9F9" cellpadding="0" width="600" style="border-spacing:20px 0;color:#4d4d4d;font-family:Arial,Helvetica">
                <tbody>
                    TROLLOLOLL
                    {% block body_html %}

                    {% endblock body_html %}
                </tbody>
            </table>
            <table align="center" bgcolor="#FFFFFF" width="600" style="margin-top:12px;color:#bdbdbd;font-family:Arial,Helvetica;font-size:11px;text-align:justify">
                <tbody>
                    <tr>
                        <td colspan="4" style="padding-top:10px">
                            This e-mail is intended solely for the addressee, may contain propriertary and legally privileged information. 
                            If you have received this e-mail by mistake please notify the sender and delete this e-mail along with all attachments. 
                            Thank you.
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

The email I'm trying to expand using my template is located in UserBundle / Resources / views / Resetting / resetting_email.html.twig and looks like this:

{% extends '::email_base.html.twig' %}

{% block subject %}Resseting password
{% endblock %}

{% block body_html %}
    <tr>
        <td colspan=2 style="text-align: left;">
            <h3>Witaj {{ user.username }}</h3>
        </td>
    </tr>
    <tr>
        <td colspan=2>
            <p>Jeśli chcesz zresetować hasło, kliknij w następujący link <a style="color: #EA2227; text-decoration: underline" href="{{ confirmationUrl }}">reset hasła</a>.</p>
        </td>
    </tr>
{% endblock body_html %}

The problem is that when I send this message, I can only see the contents with resetting_email.html.twig. And generally there is no content from base_email.html.twig.

resetting_email.html.twig:

fos_user:
    db_driver: orm 
    firewall_name: main
    user_class: GL\UserBundle\Entity\User

    from_email: 
        address:  development@##########.pl
        sender_name:  Admin ##########

    resetting:
        email:
            template:   GLUserBundle:Resetting:resetting_email.html.twig
    service:
        mailer: fos_user.mailer.twig_swift

- , ?

+4
2

.

FOSUSerBundle Twig:

protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
{
    $template = $this->twig->loadTemplate($templateName);
    $subject = $template->renderBlock('subject', $context);
    $textBody = $template->renderBlock('body_text', $context);
    $htmlBody = $template->renderBlock('body_html', $context);

    $message = \Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom($fromEmail)
        ->setTo($toEmail);

    if (!empty($htmlBody)) {
        $message->setBody($htmlBody, 'text/html')
            ->addPart($textBody, 'text/plain');
    } else {
        $message->setBody($textBody);
    }

    $this->mailer->send($message);
}

:

    $subject = $template->renderBlock('subject', $context);
    $htmlBody = $template->renderBlock('body_html', $context);

, , . , .

, body_html,

{% block body_html %}
<div dir="ltr" style="display: block; width: 100%; background: #ffffff">
...
</div>
{% endblock body_html %}
+2

, . {% block body_html %} embed. (, extends do) .

{% block body_html %}

    {% embed '@MyCompany/Mails/Grouped/base.html.twig' %}
        {% set header = "some variable defined in the template" %}

        {% block content %}
            Confirm your email bla-blah-blah
        {% endblock %}

    {% endembed %}

{% endblock %}
+2

All Articles