1

Is there a way to obfuscate an email address link that's generated by a global variable? I tried using Sprout's Encode Email, but it doesn't seem to work with an email address I've generated by a global variable. Specifically, the global variable doesn't work within an anchor tag. For example, the following doesn't work with Sprout's Encode Email:

{% set email = "<a href='mailto:{{ emailContact.emailField }}'>{{ emailContact.emailField }}</a>" %}
{{ email | rot13 }}

In the code above, "emailContact" is the global set and "emailField" is the associated handle for the actual email address.

It'd be great to figure this one out, especially because it seems a lot of folks would want to use a global variable for a contact email address. Thanks!

1
  • What does the filter output? Also do you have dev mode enabled?
    – Fyrebase
    Dec 5 '16 at 6:51
2

It might be that you're trying to parse the variables within quotes " as you set email so you're actually encoding {{ emailContact.emailField }} as a string, not the value it represents. Something like this should work:

{% set email = "<a href='mailto:" ~ emailContact.emailField ~ "'>" ~ emailContact.emailField ~ "</a>" %}

{{ email|rot13 }}
1

If you're using the SEOmatic plugin, it exposes an encodeEmailAddress() function that you can use in your templates:

https://github.com/nystudio107/seomatic/wiki/15.-Utility-Filters-&-Functions#encodeemailaddress

1

There is also this EmailObfuscate plugin for Craft CMS which seems to add obfuscation via filter on strings.

{{ entry.body|emailObfuscate }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.