How can I access data values in a kirbytag in an email template?

Hi there!

On my page I have a sign-up form. On submitting, an email is sent out to the new users.
I want to allow the editors to compose and change the text of this welcome email. Simple enough, I have a panel page, where they have a text area field that gets passed on to the email template via a data attribute.

However, as the email needs to address the new users by name, I need to include a custom kirbytag for that name, something like Dear (newuser: foo), welcome to our page!. (foo does not have any meaning it’s just there to make the kirbytag work).

Now, when I just return a string in my kirbytag it works as expected. But I do want to include the first name of the new user in the tag. I have the firstname saved in the the data array that is sent to the email template, so in the template I could access it via $firstname. How do I use it in the kirbytag though? Something like $tag->parent()->firstname() does not work (and I did not really expect it to).

Any other way to make this work?

Thanks!

You don’t use it in the KirbyTag. In fact, I wouldn’t even use a KirbyTag, but a placeholder like {{ user }}.

Then, in your email template, use Str::template() to replace the placeholder in $text with the value of $firstname.

<?= Str::template($text, [
  'user'   => $firstName
]);
?>

Thanks a lot, @texnixe, didn’t know about these placeholders. Works like a charm!