Yep, I know, there are numerous previous threads about the same topic. However, things that happended when I added a couple of banners (via javascript) got me really confused, so please help me to get this sorted out once and for all.
I use the latest version (1.6.6) and attempted to add external javascripts through global content blocks without using the {literal} tag, one of the javascript banners had this format:
var uri = 'http://impse.tradedoubler.com/imp?type( ... a(1234567)' + new String (Math.random()).substring (2, 11);
document.write('');
So what happened when I loaded the page after adding this code?
Well, except for getting error messages like this at the very top:
string(120) "Smarty error: [in tpl_body:23 line 10]: syntax error: invalid attribute name: '=' (Smarty_Compiler.class.php, line 1550)" string(153) "Smarty error: [in tpl_body:23 line 10]: syntax error: invalid attribute name: 'Grs1HHKznjUZN4KIq8jPnNRwAMd"start"' (Smarty_Compiler.class.php, line 1550)"
CMSMS also changed code in the menu manager and template!! I noticed that $node->url got something that looked like a hash added which prevented any links to work. A strange observation was that after reloading the page, the Smarty error message disappeared, until a new javascript was added and so on.
The reason I didn't use the {literal} tag was because I thought that it only is needed if the actual included code contains {} chars, which the above example doesn't. I think it would be weird to get Smarty errors since the javascript is runned at the client, not at the web server. However, the problem seems to have disappeared after enclosing the javascripts within {literal}. Adding to the mystery, I've included other javascript code without using {literal} on other CMSMS installations without any issues.
Please, once and for all, explain to me if and why I need to use the {literal} tag when adding code that doesn't include any {} chars.
Also, if you have some explanation for the mentioned spooky behavior that occured after loading the javascript without {literal} tags, I would be very thankful.
When to use {literal} tag?
Re: When to use {literal} tag?
Hello,
I can probably help you here as I've been using smarty for a long time, even before I discovered this great cms.
You are right that in the specific case of curly braces that the literal tag should be used, but I've found a number of other things that can confuse the template parser. Any piece of js that assigns variables can have this effect and, from the error message you had, it looks like that's exactly where it got tripped up.
As a general rule, I put literal tags around anything but the very simplest javascript. It won't hurt and only takes a moment.
Hope this helps.
Mark.
I can probably help you here as I've been using smarty for a long time, even before I discovered this great cms.
You are right that in the specific case of curly braces that the literal tag should be used, but I've found a number of other things that can confuse the template parser. Any piece of js that assigns variables can have this effect and, from the error message you had, it looks like that's exactly where it got tripped up.
As a general rule, I put literal tags around anything but the very simplest javascript. It won't hurt and only takes a moment.
Hope this helps.
Mark.