Twig_Error_Syntax: A message inside a trans tag must be a simple text post

Quick tip:

When have a code like this:

{% trans %}prefix.{{ varname }}{% endtrans %}

And receive this error:

Twig_Error_Syntax: A message inside a trans tag must be a simple text

You can use the following piece of code as workaround.

{{ ("prefix." ~ varname)|trans }}

PS: maybe this is not the best way to go.

Tags: php, symfony2, twig

Comments

comments powered by Disqus