Defining email template with text or html type in plugin

#1

Hi,

I want to register an email template in my plugin. And I have a text and a html variant.

But i dont think i register these templates in my plugin.

I created the follwing files in my plugin:
/templates
/emails
/mail.html.php
/mail.text.php

And in my plugin registration i have this:

    'template' => [
        'emails/mail' => __DIR__.DS.'/templates/emails/mail.php',
     ]

But my email template is never found. Which is correct of course because the mail.php doesbn’t exist.
But now i cant send mails using this code:

 kirby()->email([
                'template' => 'mail',
                'data' => [
                    'body' => $body,
                ],
            ]);

Can i create html/text email templates in my plugin?
Or is it missing for now in the plugin registration.

0 Likes

#2

@Willem I just saw that we overlooked your issue completely. Apologies. Have you resolved it already? If not, let me know and we will have another look!

0 Likes

#3

Is there a solution for this issue?

0 Likes

#4

This might be realted to: https://github.com/getkirby/kirby/issues/1459

0 Likes

#5

It should actually work, but there is an error in the above code snippet

This:

   'template' => [
        'emails/mail' => __DIR__.DS.'/templates/emails/mail.php',
     ]

Should be:

<?php

Kirby::plugin('yourname/yourplugin',[
    'templates' => [
        'emails/mail' => __DIR__. '/templates/emails/mail.php',
     ]
]);

So not template but templates and not a directory separator plus a slash.

0 Likes

#6

If i have more than one template?

0 Likes

#7

Just register the others as well, I guess:

<?php

Kirby::plugin('yourname/yourplugin',[
    'templates' => [
        'emails/mail' => __DIR__. '/templates/emails/mail.php',
        'emails/another' => __DIR__.'/templates/emails/another.php'
     ]
]);
1 Like

#8

oops! I was confused! What a bad question! :slight_smile:

0 Likes

#9

The only thing that doesn’t seem to be possible is to register both a plain text and an HTML version under the same template name, or at least I don’t know how.

0 Likes

#10

Registering both a plain text and an html version works like this:

Kirby::plugin('your/plugin', [
    'templates' => [
        'emails/email.html' => __DIR__ . '/templates/email.html.php',
        'emails/email.text' => __DIR__ . '/templates/email.text.php'
    ]
]);
0 Likes