Path Twig Strange conversion of the string Symfony 2.3

278 views Asked by At

I have this variable

   {% set slug_profilo_segnalato = '{slug_profilo_segnalato}' %}

(i assign {slug_profilo_segnalato} via sugar.js with assign. (http://sugarjs.com/api/String/assign) if i do {{slug_profilo_segnalato}}, i see correct (p.e william)

<a href='{{ path('profilo', {'slug': slug_profilo_segnalato }) }}'

when I look at the link I generated this result

.../profilo/%7Bslug_profilo_segnalato%7D

To solve this problem I did the following:

 <a href='{{ path('profilo', {'slug': slug_profilo_segnalato })|replace({'%7B':'{', '%7D':'}'}) }}'>PROFILO</a>

The results on Twig:

../profilo/william

I do not think that is the best solution. i try also |raw, spaceless.. Why is encoded in this way?

2

There are 2 answers

1
Jovan Perovic On

Have you tried combining autoescape block and raw filter?

{% autoescape false %}
    <a href='{{ path('profilo', {'slug': slug_profilo_segnalato|raw }) }}'
{% endautoescape %}

Hope this helps...

2
Lazy Ants On

%7B and %7D means you have the value with braces like this one "{something_here}" that means sugarjs don't remove braces or twig method path runs before sugarjs