4 .. versionadded:: 1.12.3
5 Support for encoding an array as query string was added in Twig 1.12.3.
7 The ``url_encode`` filter percent encodes a given string as URL segment
8 or an array as query string:
12 {{ "path-seg*ment"|url_encode }}
13 {# outputs "path-seg%2Ament" #}
15 {{ "string with spaces"|url_encode(true) }}
16 {# outputs "string%20with%20spaces" #}
18 {{ {'param': 'value', 'foo': 'bar'}|url_encode }}
19 {# outputs "param=value&foo=bar" #}
23 Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass
24 ``true`` as the first parameter) or the `http_build_query`_ function.
26 .. _`urlencode`: http://php.net/urlencode
27 .. _`rawurlencode`: http://php.net/rawurlencode
28 .. _`http_build_query`: http://php.net/http_build_query