Skip to content

Instantly share code, notes, and snippets.

@waako
Forked from olets/domain-from-url.twig
Created April 18, 2018 09:43
Show Gist options
  • Save waako/537e85361dba73bd5212716ad2aab540 to your computer and use it in GitHub Desktop.
Save waako/537e85361dba73bd5212716ad2aab540 to your computer and use it in GitHub Desktop.
get the domain from a url (twig)
{% 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