Last Updated: February 25, 2016
·
4.208K
· rogerthomas84

rawurlencode in Twig

{% set my_name = "Pro Tip" %}

{{ my_name|url_encode }}

Shows: Pro+Tip

{{ my_name|url_encode(true) }}

Shows: Pro%20Tip

2 Responses
Add your response

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

over 1 year ago ·

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 ·