Render an email template programatically
2
Inspired by the following October trick from OFFLINE: Render an e-mail template in the browser
The following code allows you to programatically render an email template. You can place this within your controller, or as the response to a route, or as a variable for a page or layout template.
// Within your use cases
use System\Classes\MailManager;
use System\Models\MailLayout;
use System\Models\MailTemplate;
// The code
$data = [
'key' => 'value',
'foo' => 'bar',
];
$layout = new MailLayout;
$layout->fillFromCode('default'); // Change this to use another layout.
$template = new MailTemplate;
$template->layout = $layout;
$template->fillFromView('winter.plugin::mail.templates.your-template'); // Use the mail template code here.
$mailContent = MailManager::instance()->renderTemplate($template, $data);
There are no comments yet
Be the first one to comment