skip to Main Content

We’re looking for a new way to create multi language email templates. We got the idea to use inky in twig to create clean email HTML and render translations. The problem is that we have Sendgrid (handlebars) that renders variables the same way as twig.

Is there a solution to create a translation in twig having the {{ }} intact. We don’t want to translate around the brackets because that could not be compatible with the language its spelling.

example

{% trans %}I am a {{ job }}{% endtrans %}

gives the following error:

A message inside a trans tag must be a simple text.

2

Answers


  1. You can use the verbatim tag to escape twig delimiters (or raw in twig 1 and 2).

    The verbatim tag marks sections as being raw text that should not be parsed.

    {% trans %}
        {% verbatim %}
            I am a {{ job }}
        {% endverbatim %}
    {% endtrans %}
    

    Another simple way would be to just output your twig delimiters as a string :

    {% trans %}I am a {{ '{{' }} job {{ '}}' }}{% endtrans %}
    
    Login or Signup to reply.
  2. You could simply fix this by using the filter option:

    {{ 'i am {{ job }}'| trans({},'domain') }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search