Render email template as virtual page


i try to render an email template as a virtual page (preview of mail).

is there a way i can pass the data to the template like in $kirby->email() ?

'pattern' => 'preview-mail',
'action' => function () {
	return new Page([
	  'slug' => 'virtual-email',
	  'template' => 'emails/default',
	  'content' => [
		'headline' => 'This is not a real mail',
		'text'  => 'Believe it or not, this mail is not real'

does not work. I replaced ‘content’ with 'data with the same result.



Not sure may be you can try controller for the email template:

Is the issue only that the content/data is not passed? The template actually loads as virtual page?

Yes, that’s the only problem.

Ok, and now I see that email templates would expect them as variables e.g. <?= $headline ?> while as virtual page you’ll get those values as <?= $page->headline ?>

So you could indeed try a controller as suggested by @ahmetbora.
Or in your templates you write fallbacks, so it works for both use cases

<?= $headline ?? $page->headline() ?>


i went with fallbacks for the variables because i have more then one mail template to preview.

i was just wondering why (or if) it was not possible to pass those variables to the email template.

In my function to send this mail i can pass them via data = ['headline => 'Some text'].

Anyways… thanks for the help (also to @ahmetbora ).

That would be the controller way that Ahmet pointed you to.