forked from twigphp/Twig
-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let url_encode filter also accept array of query parameters
- Loading branch information
Showing
4 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
``url_encode`` | ||
============== | ||
|
||
The ``url_encode`` filter URL encodes a given string: | ||
.. versionadded:: 1.12.3 | ||
Support for encoding an array as query string was added in Twig 1.12.3. | ||
|
||
The ``url_encode`` filter percent encodes a given string as URL segment | ||
or an array as query string: | ||
|
||
.. code-block:: jinja | ||
{{ data|url_encode() }} | ||
{{ "path-seg*ment"|url_encode }} | ||
{# outputs "path-seg%2Ament" #} | ||
{{ {'param': 'value', 'foo': 'bar'}|url_encode }} | ||
{# outputs "param=value&foo=bar" #} | ||
.. note:: | ||
|
||
Internally, Twig uses the PHP `urlencode`_ function. | ||
Internally, Twig uses the PHP `urlencode`_ or the `http_build_query`_ function. | ||
|
||
.. _`urlencode`: http://php.net/urlencode | ||
.. _`http_build_query`: http://php.net/http_build_query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
"url_encode" filter | ||
--TEMPLATE-- | ||
{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode }} | ||
{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode|raw }} | ||
{{ {}|url_encode|default("default") }} | ||
--DATA-- | ||
return array() | ||
--EXPECT-- | ||
foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa+ce= | ||
foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa+ce= | ||
default |