luke-nehemedia / craft-emailobfuscator

A simple email obfuscate plugin (using rot13) for CraftCMS3
MIT License
3 stars 1 forks source link

mailto: links #1

Closed bleepsandblops closed 6 years ago

bleepsandblops commented 6 years ago

Hello,

Thanks for the plugin. Is it meant to work on mailto links? As I've tried it a few different ways and it just produces some mangled code...

Thank you!

luke-nehemedia commented 6 years ago

Hello!

Yes it should work on mailto links.

Can you tell me a little bit more about how your template looks like?

Is the JS-File included correctly?

bleepsandblops commented 6 years ago

Thanks for getting back so quickly, yeah I can see it's working for the actual email that's within the a tag.

What syntax would you use? Is the | obfuscateEmail meant to apply to the whole <a href="email@email.com">email@email.com</a> link?

luke-nehemedia commented 6 years ago

Yes, you should be able to use it on the whole tag.

In fact, you can use it on formatted textfields, so this should work.

I can take a look on the code on Saturday.

bleepsandblops commented 6 years ago

Argh I'm really sorry, it's working now...

If anyone's reading this, this is the syntax that worked for me: {{ "<a href=\"mailto:test@test.com\">test@test.com</a>" | obfuscateEmail }}

kaspar-allenbach commented 6 years ago

How is this suposed to be writen when the email is in a field:

That is not working: {{ "<a href=\"mailto:" ~ entry.adrEmail ~ \">" ~ entry.adrEmail ~ "</a>"" | obfuscateEmail }}

luke-nehemedia commented 6 years ago

There are multiple mistakes here that have to do with twig, not the plugin.

First of all, you have some unclosed strings. It should look like this:

"<a href=\"mailto:" ~ entry.adrEmail ~ "\">" ~ entry.adrEmail ~ "</a>"

However, obfuscateEmail does only work on the "</a>" part. To make this work you have to place the whole string into parentheses:

{{ ("<a href=\"mailto:" ~ entry.adrEmail ~ "\">" ~ entry.adrEmail ~ "</a>") | obfuscateEmail}}

You can also first save this string to a variable and then print it out where needed. This might look cleaner and is reusable. However, both methods work.

{% set link = "<a href=\"mailto:" ~ entry.adrEmail ~ "\">" ~ adrE entry.adrEmail ail ~ "</a>" %}
{{ link | obfuscateEmail }}