URL filters allow you to build or extract parts of URLs.

add_query

Appends a query string parameter to a URL. If the parameter already exists in the URL, the parameter value will be updated.

If this filter is applied to a full absolute URL, an updated absolute URL will be the result. If it is applied to a path, an updated path will be the result.

Code
{{ 'http://example.com/path?page=1' | add_query: 'foo', 'bar' }}
{{ '/path?page=1' | add_query: 'page', 2 }}
Output
http://example.com/path?page=1&foo=bar
/path?page=2

base

Gets the base URL of a given URL.

Code
{{ 'http://example.com/path?foo=bar&page=2' | base }}
Output
http://example.com

host

Gets the host part of a URL.

Code
{{ 'http://example.com/path?foo=bar&page=2' | host }}
Output
example.com

path

Gets the path part of a URL.

Code
{{ 'http://example.com/path?foo=bar&page=2' | path }}
{{ '/path?foo=bar&page=2' | path }}
Output
/path
/path

path_and_query

Gets the path and query part of a URL.

Code
{{ 'http://example.com/path?foo=bar&page=2' | path_and_query }}
{{ '/path?foo=bar&page=2' | path_and_query }}
Output
/path?foo=bar&page=2
/path?foo=bar&page=2

port

Gets the port number of a URL.

Code
{{ 'http://example.com/path?foo=bar&page=2' | port }}
{{ 'https://example.com/path?foo=bar&page=2' | port }}
{{ 'https://example.com:9000/path?foo=bar&page=2' | port }}
Output
80
443
9000

remove_query

Removes a query string parameter from a URL. If the parameter does not exists in the URL, the URL will be returned unchanged.

If this filter is applied to a full absolute URL, an updated absolute URL will be the result. If it is applied to a path, an updated path will be the result.

Code
{{ 'http://example.com/path?page=1' | remove_query: 'page' }}
{{ '/path?page=1' | remove_query: 'page' }}
Output
http://example.com/path
/path

scheme

Gets the scheme part of a URL.

Code
{{ 'http://example.com/path?foo=bar&page=2' | scheme }}
{{ 'https://example.com/path?foo=bar&page=2' | scheme }}
Output
http
https