I want to add a <script> line in wich { tags are used:
<script language=javascript>h1 = document.getElementsByTagName('h1');if(h1.length > 0){h1=escape(h1[0].innerText);}else{h1='';};document.write
etc.
How can I escape the { tags so this code won't call smarty?
Regards, Robin
Posts: 27300
Move to the G2 forum. No smarty in G1. :wink:
Dave
Posts: 328
juro, take a look at the smarty documentation. The function you want is {literal}...{/literal}. Note that you can't use other smarty tags inside this block. If you need that, you have to replace all {'s and }'s with {ldelim} and {rdelim}.
floridave, thanks!
Posts: 113
Would { and } work also? They're the HTML-escaped versions of { and } respectively.
lol ... the forums changed it for me. I meant: & #123; and & #125; without the spaces between & and #
I've never tried using them to replace { in a script ... and it's probably faster to just use {literal} ... {/literal} ... but it's the first thing that came to my mind ;)
Posts: 7994
Unfortunately, if you use the html entities (& #123; and & #125;) then the Javascript engine won't parse them as open and close braces and will treat them as syntax errors. Eg:
I generally use {literal}. However, you can also use {ldelim} and {rdelim} for open and close braces, which is useful if you want to intersperse Smarty tags inside your Javascript. We do that in a few places in the code.
Posts: 113
Figured as much. Thanks for letting me know