Stevie
March 10, 2020, 7:53pm
1
Hi all!
How to use t (‘varialbe’) in email templates?
I tried like this, but it doesn’t work:
$kirby->setCurrentLanguage('en');
$kirby->email([
'template' => $template,
'to' => $to,
'from' => $site->email_from()->value(),
'replyTo' => $site->email_from()->value(),
'subject' => $subject,
'data' => [
'data' => $data
],
]);
and in email template
<h2><?= t('accept_text') ?></h2>
I think your email template doesn’t know anything about the current language, it would probably make more sense to pass the variable to the template via the data array.
Maybe it can be done with routing? But v3.3.5 needs to be used.
Stevie
March 11, 2020, 9:20am
4
Thanks texnixe!
I tried this option now:
$kirby->setCurrentLanguage('en');
$kirby->email([
'template' => "accept",
'to' => $data->email()->value(),
'from' => $site->email_from()->value(),
'replyTo' => $site->email_from()->value(),
'subject' => $subject,
'data' => [
'data' => $data,
'lang' => $lang,
'text' => t('accept_text'),
'worktitle' => t('worktitle'),
'email' => t('email'),
'phone' => t('phone'),
'entity' => t('entity')
],
]);
and email template:
<?= $text ?>
But does not work (
Language does not switch.
Stevie
March 11, 2020, 9:42am
5
tried to make a test controller:
<?php
return function ($kirby, $page) {
$kirby->setCurrentLanguage('en');
$kirby->email([
'template' => 'accept',
'to' => 'test@me.com',
'from' => 'noreply@site.com',
'replyTo' => 'noreply@site.com',
'subject' => 'test',
'data' => [
'data' => array(),
'lang' => 'en',
'text' => t('accept_text'),
'worktitle' => t('worktitle'),
'email' => t('email'),
'phone' => t('phone'),
'entity' => t('entity')
],
]);
return compact('page');
};
Language did not switch
Could you try following?
$kirby->setCurrentTranslation('en');
$kirby->setCurrentLanguage('en');
Stevie
March 11, 2020, 10:12am
8
Thanks byybora !
$kirby->setCurrentTranslation('en');
work fine!