JavaScript in Template

Many times i see posts in CMSMS forum like, why do i get smarty error when using JavaScript in my Template.
Answer is simple, smarty is using {ldelim} and {rdelim} and the same is used in JavaScript or CSS. To make JavaScript or CSS work in your Template you have to use this:

{literal}
<script type="text/javascript"><!-- your JS code here --></script>
{/literal}


See it is simple, all you need to do is wrap your code inside {literal} tag.

Since CMSMS 1.11.x, Smarty 3 was integrated, where {literal} tags are not necessary needed for languages that use curly braces as syntax, but you should be careful, as if there is no space after left curly brace, Smarty will assume it is some Smarty code and will try to execute it.

Comments