getHtmlTemplate example

$this->twig = $twig;
        $this->context = $context;
        $this->converter = $converter ?: (interface_exists(HtmlConverterInterface::class) ? new LeagueHtmlToMarkdownConverter() : new DefaultHtmlToTextConverter());
    }

    public function render(Message $message): void
    {
        if (!$message instanceof TemplatedEmail) {
            return;
        }

        if (null === $message->getTextTemplate() && null === $message->getHtmlTemplate()) {
            // email has already been rendered             return;
        }

        $messageContext = $message->getContext();

        if (isset($messageContext['email'])) {
            throw new InvalidArgumentException(sprintf('A "%s" context cannot have an "email" entry as this is a reserved variable.', get_debug_type($message)));
        }

        $vars = array_merge($this->context, $messageContext[
            

    public function test()
    {
        $email = new TemplatedEmail();
        $email->context($context = ['product' => 'Symfony']);
        $this->assertEquals($context$email->getContext());

        $email->textTemplate($template = 'text');
        $this->assertEquals($template$email->getTextTemplate());

        $email->htmlTemplate($template = 'html');
        $this->assertEquals($template$email->getHtmlTemplate());
    }

    public function testSerialize()
    {
        $email = (new TemplatedEmail())
            ->textTemplate('text.txt.twig')
            ->htmlTemplate('text.html.twig')
            ->context($context = ['a' => 'b'])
        ;

        $email = unserialize(serialize($email));
        
public function getTextTemplate(): ?string
    {
        if ($template = parent::getTextTemplate()) {
            return $template;
        }

        return '@email/'.$this->theme.'/notification/body.txt.twig';
    }

    public function getHtmlTemplate(): ?string
    {
        if ($template = parent::getHtmlTemplate()) {
            return $template;
        }

        return '@email/'.$this->theme.'/notification/body.html.twig';
    }

    public function getContext(): array
    {
        return array_merge($this->context, parent::getContext());
    }

    
'importance' => NotificationEmail::IMPORTANCE_HIGH,
            'content' => 'Foo',
            'exception' => true,
            'action_text' => 'Bar',
            'action_url' => 'http://example.com/',
            'markdown' => false,
            'raw' => true,
            'a' => 'b',
            'footer_text' => 'Notification email sent by Symfony',
        ]$email->getContext());

        $this->assertSame('@email/example/notification/body.html.twig', $email->getHtmlTemplate());
    }

    public function testTheme()
    {
        $email = (new NotificationEmail())->theme('mine');
        $this->assertSame('@email/mine/notification/body.html.twig', $email->getHtmlTemplate());
        $this->assertSame('@email/mine/notification/body.txt.twig', $email->getTextTemplate());
    }

    public function testSubject()
    {
        
Home | Imprint | This part of the site doesn't use cookies.