Including JavaScript Code

JavaScript gives very wide opportunities to make dynamic pages on your site. There are no reasons to avoid using of JavaScript code in online store layout templates. The only point you should remember is that Smarty template engine uses curly brackets ({}) to enclose placeholders. When Smarty encounters these tags, it attempts to interpret them, and display the appropriate output in their place. In case of JavaScript, it is necessary to escape curly brackets. Use {literal}...{/literal} blocks to escape curly brackets. Similar to HTML entity usage, you can use {ldelim}, {rdelim} or {$smarty.ldelim} tags to display the current delimiters.

Important: Make sure that curly brackets are escaped in the JavaScript code. Such a problem is hard to be troubleshot as errors are output only to log file on the store server. In case of this error you find only a white screen instead of HTML page.

Examples

<script type=”text/javascript”>
<!-- The whole function code is declared as literal content -->
{literal}
function show_example() {
   // any code here
}
{/literal}
</script>
<script type=”text/javascript”>
<!-- Curly brackets are replaced with {ldelim} and {rdelim} tags -->
function show_example() {ldelim}
   // any code here
{rdelim}
</script>