Archive for JavaScript

JavaScript In Smarty

Just before I gave up with Serendipity – which uses the Smarty templating engine – I was trying to add some Google Analytics code into the template.  Because GA creates an anonymous function in JavaScript, instead of simply including the remote JS source file (which does make sense, in reality), it includes curly braces — and Smarty hates that.  It prompted me with errors about unknown tags and stuff.  Hooray.

Well, thankfully, the fix was simple: wrap the JavaScript code in ‘literal’ tags.  Example:


{literal}
<script language="JavaScript">
alert('Smarty takes this literally.');
</script>
{/literal}