it7e1q
Last Updated: February 25, 2016
·
1.515K
· rogerthomas84
F7dd62ed2ab71c8d130819dd0b560a65

rawurlencode in Twig

{% set my_name = "Pro Tip" %}

{{ my_name|url_encode }}

Shows: Pro+Tip

{{ my_name|url_encode(true) }}

Shows: Pro%20Tip

Say Thanks
Respond

2 Responses
Add your response

7256
A06c38dd3377bbc0db360c44a2969fed

What's the "true" actually referring to here? (I would have thought that the default behaviour anyway)

over 1 year ago ·
7257
F7dd62ed2ab71c8d130819dd0b560a65

It's the type of encoding used on the characters. Its the difference between urlencode() and rawurlencode() in PHP. rawurlencode formats strings according to RFC 3986.
Unfortunately twig doesn't seem to care about using logic. Plus the fact that even the twig documentation fails to tell us that url_encode can even take the true param.

over 1 year ago ·