Last active
September 13, 2024 11:35
-
-
Save olets/a835d4f8df5028fb30649d6a8aa03de2 to your computer and use it in GitHub Desktop.
get the domain from a url
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
{% set no_protocol = url|split('//')[1] ?: url %} | |
{% set only_domains = no_protocol|split('/')[0] ?: no_protocol %} | |
{% set url_domain = '' %} | |
{% if only_domains|split('.')[2] %} | |
{% set url_domain = only_domains|split('.')[1] %} | |
{% else %} | |
{% set url_domain = only_domains|split('.')[0] %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead, try this one:
Always test your code before publishing: https://twigfiddle.com/phdhbi