On a website I was working on recently I added the Google Analytics tracking code to the footer of a Smarty template, like this:

footer.tpl:



However, since the javascript used by Google Analytics includes { and } tags, also used by the Smarty template engine, it tries to interpret this code and depending on your settings will either fail silently or or with an error such as this:

Smarty error: [in footer.tpl line 148]: syntax error: unrecognized tag 'var'

The fix is simple. Enclose your Google Analytics code, or other javascript code, with {literal} and {/literal}. The literal tag allows you to place code to be displayed, well, literally.

The final code will look something like this:


{literal}

{/literal}



Your website should now run properly with the Google Analytics code in place.

You May Also Like

Comprehensive .htaccess guide

The AskApache blog has a great comprehensive guide to .htaccess. A must…

.htaccess stupid tips and tricks

Found an encyclopedic list of “stupid” .htaccess tricks. Includes many useful ones…

How We Defeated a Proxy Jacker (Google Web Spam Syndrome)

A few months ago, we had an interesting issue with another website…

Adding a Module Position in a Joomla 1.5 Template

Adding a module position in a Joomla 1.5 template is not as…