October CMS resources and help articles

Simple and to the point. Optimized by the community.

Render an e-mail template in the browser

5
by OFFLINE, last modified on January 8th, 2020

To preview an e-mail template directly in the browser, add a temporary route to your plugin's routes.php file:

// plugins/yourvendor/yourplugin/routes.php

use System\Classes\MailManager;
use System\Models\MailLayout;
use System\Models\MailTemplate;

Route::get('/mail', function () {
    $data = [
        'your-dummy' => 'data',
    ];

    $layout = new MailLayout;
    $layout->fillFromCode('default'); // Change this to use another layout.

    $template = new MailTemplate;
    $template->layout = $layout;
    $template->fillFromContent(File::get(base_path('plugins/path/to/your/views/template.htm')));

    return MailManager::instance()->renderTemplate($template, $data);
});

Now visit http://yoursite.test/mail to preview the mail in your browser. Don't forget to remove this route once you are done!

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?