# Handling declensions in emails

**URL:** <https://forum.mautic.org/t/handling-declensions-in-emails/14482>\
**Category:** Product Support\
**Created:** [May 25, 2020, 1:49am UTC](https://forum.mautic.org/t/handling-declensions-in-emails/14482 "2020-05-25T01:49:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kacpers](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kacpers/32/1848_2.png) [@kacpers](https://forum.mautic.org/u/kacpers)\
**Post date:** [May 25, 2020, 1:49am UTC](https://forum.mautic.org/t/handling-declensions-in-emails/14482/1 "2020-05-25T01:49:26Z")

</div>

Dear Folks,

I run a small guesthouse and I’m setting up Mautic to take over most of the repetitive, guest related communication.

**My software**  
Mautic 2.16.1  
PHP 7.3

**My problem**  
My audience is mainly Polish (according to some [the most difficult language there](https://claritaslux.com/the-hardest-language-to-learn/)) and we have seven cases for both pronouns and names.

Implications are, that depending on the context:

- my name is Kacper, Kacpra, Kacprowi, Kacpra, Kacprem, Kacprze or Kacprze
- singular, masculine pronoun is Pan, Pana, Panu, Pana, Panem, Panu or Panie

I compiled a database of 3000+ Polish names declensions and another one with 35 possible pronouns.

They are all scattered across a series of many emails. They are often parts of a dynamic content blocks inserted through Code Mode.

What’s the best way to merge it?

**Starting points**  
I’m happy with neither, but I have no other ideas. I’m hoping you folks will help me come up with something smarter.

1. Custom Fields for each Contact to hold all the cases, inserted through {contactfield=firstname-dative} or {contactfield=pronoun-dative}. Issues:  
- mess due to 14/21 additional fields for each contact  
- automatically populating fields with the right values
2. Dynamic Content for the pronouns, inserted through {dynamiccontent=“Dynamic Content n”}. Issues:  
- messy code due to breaking large content containers into many small ones  
- mess in a dynamic content tab  
- labour intensive to implement - every email will have to have a copy of the same dynamic content boilerplate to set up  
- painful to maintain/update in case of bugs - every change will have to be made in every email

---

<div class="post-metadata">

**Author:** ![ekke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ekke/32/296_2.png) [@ekke](https://forum.mautic.org/u/ekke)\
**Post date:** [May 25, 2020, 4:53am UTC](https://forum.mautic.org/t/handling-declensions-in-emails/14482/2 "2020-05-25T04:53:27Z")

</div>

Just an association: Dud you look at [https://github.com/Logicify/mautic-advanced-templates-bundle](https://github.com/Logicify/mautic-advanced-templates-bundle) ?

---

<div class="post-metadata">

**Author:** ![kacpers](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kacpers/32/1848_2.png) [@kacpers](https://forum.mautic.org/u/kacpers)\
**Post date:** [May 25, 2020, 6:10am UTC](https://forum.mautic.org/t/handling-declensions-in-emails/14482/3 "2020-05-25T06:10:08Z")

</div>

Hey @ekke, it looks promising. I have never touched PHP, but I learned Handlebars once, so I’ll try to learn Twig from their documentation. I’ll let you know how it went. Thank you!

---

<div class="post-metadata">

**Author:** ![kacpers](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kacpers/32/1848_2.png) [@kacpers](https://forum.mautic.org/u/kacpers)\
**Post date:** [June 8, 2020, 4:29pm UTC](https://forum.mautic.org/t/handling-declensions-in-emails/14482/4 "2020-06-08T16:29:40Z")

</div>

Yes, after a little bit of reading and tinkering, [mautic-advanced-templates-bundle](https://github.com/Logicify/mautic-advanced-templates-bundle) seems to be the solution for both.

**Flexing names solution:**

1. Add `nameFlex` custom field in Settings
2. Set `nameFlex` value for a given contact to an array of corresponding declensions like `["Kacper", "Kacpra", "Kacprowi", "Kacpra", "Kacprem", "Kacprze", "Kacprze"]`
3. Set a variable `flex` and filter it with `json_decode` inside the TWIG block of the email.
4. Pull the chosen declension, pointing at it’s location in the array with `{{flex[6]}}`

**Pronouns solution**

1. Basic `if`, `elseif` and `else` logic.

**Example:**

```
{% TWIG_BLOCK %}

{% set flex = lead.flex | json_decode %}

{% if lead.gender == 'm' %}<p>Szanowny Panie {{flex[6]}}</p>
{% elseif lead.gender == 'f' %}<p>Szanowna Pani {{flex[6]}}</p>
{% else %}<p>Dzień dobry {{flex[6]}}</p>
{% endif %}

{% END_TWIG_BLOCK %}

```

**Output:**

`Szanowny Panie Kacprze`

Namaste 🙏
