# How to use t ('varialbe') in email templates?

**URL:** <https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 10, 2020, 7:53pm UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564 "2020-03-10T19:53:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stevie](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/stevie/32/7095_2.png) [@Stevie](https://forum.getkirby.com/u/Stevie)\
**Post date:** [March 10, 2020, 7:53pm UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/1 "2020-03-10T19:53:07Z")

</div>

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>`

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 10, 2020, 8:01pm UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/2 "2020-03-10T20:01:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [March 11, 2020, 8:54am UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/3 "2020-03-11T08:54:20Z")

</div>

Maybe it can be done with routing? But v3.3.5 needs to be used.

> **[Routing](https://getkirby.com/docs/guide/routing#multi-language-setup)**
>
> Use Kirby's router to modify URLs or provide extra functionality when the user calls an given URI pattern.

---

<div class="post-metadata">

**Author:** ![Stevie](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/stevie/32/7095_2.png) [@Stevie](https://forum.getkirby.com/u/Stevie)\
**Post date:** [March 11, 2020, 9:20am UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/4 "2020-03-11T09:20:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stevie](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/stevie/32/7095_2.png) [@Stevie](https://forum.getkirby.com/u/Stevie)\
**Post date:** [March 11, 2020, 9:42am UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/5 "2020-03-11T09:42:57Z")

</div>

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 🤔

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [March 11, 2020, 9:50am UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/6 "2020-03-11T09:50:13Z")

</div>

Could you try following?

```php
$kirby->setCurrentTranslation('en');
$kirby->setCurrentLanguage('en');

```

---

<div class="post-metadata">

**Author:** ![Stevie](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/stevie/32/7095_2.png) [@Stevie](https://forum.getkirby.com/u/Stevie)\
**Post date:** [March 11, 2020, 10:01am UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/7 "2020-03-11T10:01:31Z")

</div>

Thanks!

Now let’s try!

---

<div class="post-metadata">

**Author:** ![Stevie](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/stevie/32/7095_2.png) [@Stevie](https://forum.getkirby.com/u/Stevie)\
**Post date:** [March 11, 2020, 10:12am UTC](https://forum.getkirby.com/t/how-to-use-t-varialbe-in-email-templates/17564/8 "2020-03-11T10:12:44Z")

</div>

Thanks [byybora](https://forum.getkirby.com/u/byybora)!

`$kirby->setCurrentTranslation('en');`  
work fine!
