I use {encode="{webmaster_email}" title="Send E-Mail"}
to hide my email address from harvester bots.
When I use this code within my template all is fine. This code is also part of the footer. The footer is an early parsed variable from the Republic Variables module.
My problem is: {encode} delivers a fully functional mailto
tag, but also prints the string between the <script>
tags.
I looked at the HTML source after rendering, extraced the two {encode}
parts and compared them.
This is the code, that I get, when I put {encode}
into the template. It renders as a mailto
, as expected.
<span data-eeEncEmail_FJbRPLRqeP='1'>.(JavaScript must be enabled to view this email
address)</span><script type="text/javascript">/*<![CDATA[*/var out = '',el =
document.getElementsByTagName('span'),l = ['>','a','/','<',' 110',' 101',' 100',' 110','
101',' 115',' 32',' 108',' 105',' 97',' 77',' 45',' 69','>','\"',' 101',' 100',' 46','
97',' 105',' 100',' 101',' 109',' 116',' 117',' 107',' 105',' 100',' 110',' 97',' 98','
64',' 101',' 107',' 99',' 101',' 110',' 114',' 97',' 119','
97',':','o','t','l','i','a','m','\"','=','f','e','r','h','a ','<'],i = l.length,j =
el.length;while (--i >= 0){out += unescape(l[i].replace(/^\s\s*/, '&#'));}while (--j >=
0){/**/if (el[j].getAttribute('data-eeEncEmail_FJbRPLRqeP')){el[j].innerHTML = out;}}/*]]>*
</script>
This is the code, that I get from the {encode}
, that is part of the footer variable. This gives me a fully functional mailto
plus all the stuff between the <script>
tags gets rendered as text and appears as such on the page.
<span data-eeEncEmail_OOxdsWxRWB='1'>.(JavaScript must be enabled to view this email address)</span><script type="text/javascript">**/*<![CDATA[*/var out = '',el =
document.getElementsByTagName('span'),l = ['>','a','/','<',' 110',' 101',' 100','
110',' 101',' 115',' 32',' 108',' 105',' 97',' 77',' 45',' 69','>','\"',' 101',' 100','
46',' 97',' 105',' 100',' 101',' 109',' 116',' 117',' 107',' 105',' 100',' 110',' 97','
98',' 64',' 101',' 107',' 99',' 101',' 110',' 114',' 97',' 119','
97',':','o','t','l','i','a','m','\"','=','f','e','r','h','a ','<'],i = l.length,j =
el.length;while (--i >= 0){out += unescape(l[i].replace(/^\s\s*/, '&#'));}while (--j >=
0){/**/if (el[j].getAttribute('data-eeEncEmail_OOxdsWxRWB')){el[j].innerHTML = out;}}/*]]>*
/**</script>
I saved both to a local HTML file and letthe browser render it. I got 2 mailto-links, as expected. So, the code works.
Why does EE add the CDATA
stuff, when I put {encode}
in the footer?
EDIT: It seems to be a CSS issue. The "E-Mail me"-Link is part of an inline list in the footer. The respective CSS is
ul.inline-list > li > * { display: block; }
When I delete this line, the Javascript disappears. Just changeing to display:inline or any other display type doesn´t help. display:none makes the entire entry (the mailto plus the superflous JS) disappear.
{webmaster_email}
from the encode tag and hard code the actual email in? ie.{encode="[email protected]" title="Send Email"}
<li>
etc etc.<script>
elements are stil DOM nodes so can be affected bydisplay:block
as you've found out. Perhaps try settingul.inline-list > li { display: inline-block; }
, or if you really must use*
, do an override for script elements on the next line:ul.inline-list > li > script { display: none; }
, better to just not use*
though.ul.inline-list > li > * { display: block; }
line and since I haven´t seen any negative side effects I´m fine. I will though keep in mind what you wrote for coming projects.