Last Updated: February 25, 2016
·
4.651K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside