url_host

The url_host filter parses the URL and returns the host portion of the URL if it exists.

If a host portion of the URL cannot be found then the original value is returned.

The host value includes the full domain name and any subdomains.

For example, if the URL value is "https://www.branchcms.com" then the url_host filter would return "www.branchcms.com".

If the URL value is "https://www.names.co.uk" then the url_host filter would return "www.names.co.uk".

If the URL value is "https://branchcms.com" then the url_host filter would return "branchcms.com".

This filter can be useful if you have an app item that has a website value and you want to output a link. The website value is often unknown and can sometimes be long. Instead of defaulting to some generic text for the link (like "Website") you can instead show the host name as the link.

<a href="{{ item.website|url }}">{{ item.website|url_host }}</a>

< Back to the list of filters