Remco
Remco

Reputation: 223

Using multiple variables in symfony translation strings without whitespace

How do I use multiple variables in a symfony translation string without whitespace between them?

This example works, but it has whitespace between the variables

{% trans with {
'%name%': customer.getPlausibleFirstName(),
'%city%': customer.getCity(),
'%accentStart%': '<strong>',
 '%accentEnd%': '</strong>',
 }%}%accentStart% %name% %accentEnd% from %accentStart% %city% %accentEnd% would like a quote{% endtrans %}

What I'd really want to do is:

{% trans with {
'%name%': customer.getPlausibleFirstName(),
'%city%': customer.getCity(),
'%accentStart%': '<strong>',
 '%accentEnd%': '</strong>',
 }%}%accentStart%%name%%accentEnd% from %accentStart%%city%%accentEnd% would like a quote{% endtrans %}

This last version throws the following error:

Variable " from " does not exist in ApplicationBundle:Default:header.html.twig at line 13

How do I resolve this issue?

Upvotes: 0

Views: 835

Answers (1)

Abdallah Arffak
Abdallah Arffak

Reputation: 1193

Replace "%" by annother char example :"|"

{% trans with {
    '|name|': customer.getPlausibleFirstName(),
    '|city|': customer.getCity(),
    '|accentStart|': '<strong>',
    '|accentEnd|': '</strong>',
    }%}|accentStart||name||accentEnd| from |accentStart||city||accentEnd| would like a quote{% endtrans %}

Upvotes: 3

Related Questions