Created
April 25, 2019 23:04
-
-
Save piotrpog/8ca4285fbe509dabd9eabb2df3d0c86f to your computer and use it in GitHub Desktop.
Twig macro converting email addresses in text into links secured from spambots. More info: http://craftsnippets.com/articles/converting-email-addresses-into-links-using-twig-macro
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
{% macro emailLinks(text, class) %} | |
{# v1 #} | |
{% spaceless %} | |
{% set text = text|replace('/([a-zA-Z0-9_.+-]+)+@([a-zA-Z0-9-]+.[a-zA-Z]+)/', '<a ' ~ (class ? 'class="' ~ class ~ '" ') ~ 'href="mailto:'~ '\\1@\\2' ~'">'~ '\\1@\\2' ~'</a>') %} | |
{{text|raw}} | |
{% endspaceless %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment