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.
CodePudding user response:
You could simply fix this by using the filter option:
{{ 'i am {{ job }}'| trans({},'domain') }}
CodePudding user response:
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 %}