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

How To Turn Off Your Monitor Via Command Line in Ubuntu

As previously written on this blog, I have set up a display…

Joomla! 1.0.12 Double Pathway Bug

Joomla! 1.0.12 appears to have a pathway bug. If you use a…

Secure Your Google Apps (Gmail, GDocs, GCal, etc)

If you are a Google user – meaning Gmail, Google Docs, Google…