Skip to content

Latest commit

 

History

History
151 lines (99 loc) · 1.88 KB

url.md

File metadata and controls

151 lines (99 loc) · 1.88 KB

Url Extension

The url twig extension gives you a simple and efficient way to get specific parts of urls.

Setup

Service Registration

The twig extension need to be registered as symfony service.

services:
    Sulu\Twig\Extensions\UrlExtension: ~

If autoconfigure is not active you need to tag it with twig.extension.

Usage

Format url

You can get a specific format of any valid url

{{ 'https://www.example.org/test'|url_format({
    scheme: false,
    path: false,
}) }}

Output:

www.example.org

Get scheme

You can get the scheme of a valid url

{{ 'https://www.example.org/test'|url_scheme }}

Output:

https

Get user

You can get the user of a valid url

{{ 'ftp://admin:[email protected]'|url_user }}

Output:

admin

Get password

You can get the password of a valid url

{{ 'ftp://admin:[email protected]'|url_pass }}

Output:

hidden

Get host

You can get the host of a valid url

{{ 'example.org:8080'|url_host }}

Output:

example.org

Get port

You can get the port of a valid url

{{ 'example.org:8080'|url_port }}

Output:

8080

Get path

You can get the path of a valid url

{{ 'http://example.org/hello'|url_path }}
{{ 'example.org/hello'|url_path }}
{{ 'example.org:8080/hello'|url_path }}

Output:

hello
example.org/hello
hello

Get query

You can get the query of a valid url

{{ 'http://example.org/hello?arg=test&x=y'|url_query }}

Output:

arg=test&x=y

Get fragment

You can get the fragment of a valid url

{{ 'http://example.org/hello#test'|url_fragment }}

Output:

test