Defining email template with text or html type in plugin

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.

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

Is there a solution for this issue?

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

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.

If i have more than one template?

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

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

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.

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'
    ]
]);
4 Likes