-
-
Save toomanyredirects/51948e6266507980dafc72af511367db to your computer and use it in GitHub Desktop.
get the domain from a url
This file contains hidden or 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
{# Twig URL parser: #} | |
{% set url= 'http://subdomain.domain.tld/some/dir/file.pdf' %} | |
{% set noprotocol = url|split('//')[1] ?: url %} | |
{% set domains = noprotocol|split('/')[0] ?: noprotocol %} | |
{% if domains|split('.')[2] is defined %} | |
{% set subdomain = domains|split('.')[0] %} | |
{% set domain = domains|split('.')[1] %} | |
{% set tld = domains|split('.')[2] %} | |
{% else %} | |
{% set subdomain = '' %} | |
{% set domain = domains|split('.')[0] %} | |
{% set tld = domains|split('.')[1] %} | |
{% endif %} | |
{% set path = noprotocol|replace({(subdomain ? subdomain ~ '.' : '') ~ (domain) ~ '.' ~ (tld) :''}) %} | |
{{ domains }} | |
{{ domain }} | |
{{ subdomain }} | |
{{ tld }} | |
{{ path }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment