1

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.

3
  • What happens would remove the republic variable {webmaster_email} from the encode tag and hard code the actual email in? ie. {encode="[email protected]" title="Send Email"}
    – Siebird
    Commented Nov 28, 2012 at 18:44
  • As an aside: Using the star selector in that way is very inefficient. CSS selectors are parsed right to left, so that basically selects every DOM element in the page, then sees if it's an immediate child of an <li> etc etc. <script> elements are stil DOM nodes so can be affected by display:block as you've found out. Perhaps try setting ul.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.
    – Tom Davies
    Commented Nov 28, 2012 at 19:04
  • Thanks for the CSS-explanation. I´m using the Foundation framework for my site and that´s the CSS they provide. I just commented the 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.
    – awa
    Commented Dec 3, 2012 at 13:32

3 Answers 3

2

The <!CDATA block is only required if you need your document to be parsable as XML, for example if you're using an `XHTML~ doctype. For a full explanation of why this was necessary in the past see this stackoverflow qn.

If you're using a modern, HTML5 doctype then using <!CDATA isn't necessarily, but I'm guessing EllisLab include it in the {encode} output for backwards compatibility with sites that are using the older XHTML doctype.

I suspect the reason that the encode isn't working properly in the footer is probably still a parse order issue - if you use a snippet does it works as expected?

Scratch that: if that is the source copied direct from the outputted page it looks like in your global variable the <script> tag is getting stripped from the output, hence the content getting output as text to the page.

What version of EE are you using? Is this GV inside of a conditional? I seem to remember that there was a bug (fixed in 2.5.3) that could cause script tags to be stripped from evaluated variables.

Might still be worth trying a snippet instead of a GV just to see if that works too...

1
  • I use v2.5.3 - Build Date: 2012091, it´s not inside a conditional. I didn´t put the CDATA in th code, it comed fro the {encode}. I´m afraind, that I don´t understand your coment regardinf the <script>tat. This tag is in the code.
    – awa
    Commented Nov 28, 2012 at 18:15
1

I know this is old, but I ran into this issue and fixed it by setting "Automatically turn URLs and email addresses into links?" to "No" in the appropriate Channel's preferences page (Admin -> Channel Administration -> Channels -> Edit Preferences).

0

Try turning off the protect javascript config variable: $config['protect_javascript'] = 'n';. You can set this in /system/expressionengine/config/config.php file. This has solved similar problems for me in the past.

1
  • Sorry, this did not help. Theerror still persists
    – awa
    Commented Nov 28, 2012 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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