Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``url_encode`` |
| 2 | ============== |
| 3 | |
| 4 | The ``url_encode`` filter percent encodes a given string as URL segment |
| 5 | or an array as query string: |
| 6 | |
| 7 | .. code-block:: twig |
| 8 | |
| 9 | {{ "path-seg*ment"|url_encode }} |
| 10 | {# outputs "path-seg%2Ament" #} |
| 11 | |
| 12 | {{ "string with spaces"|url_encode }} |
| 13 | {# outputs "string%20with%20spaces" #} |
| 14 | |
| 15 | {{ {'param': 'value', 'foo': 'bar'}|url_encode }} |
| 16 | {# outputs "param=value&foo=bar" #} |
| 17 | |
| 18 | .. note:: |
| 19 | |
| 20 | Internally, Twig uses the PHP `rawurlencode`_ or the `http_build_query`_ function. |
| 21 | |
| 22 | .. _`rawurlencode`: https://secure.php.net/rawurlencode |
| 23 | .. _`http_build_query`: https://secure.php.net/http_build_query |