Tried to add some js using the 'header' option with function.pageaddvar.php in a tpl file, sth very simple like (I've added a % sign in 'script' so the following code won't be stripped off by the system when displayed)
Code
{pageaddvar name='header' value='<scr%ipt type="text/javascript">alert("header");</scr%ipt>'}
And the page doesn't render correctly. Examining the page source reveals that Smarty inserted a bunch of codes from other parts of the tpl (those below the above code) after
Code
<scr%ipt
However, using
Code
PageUtil::addVar('header', '<scr%ipt type="text/javascript">alert("header");</scr%ipt>')
in a controller file works perfectly fine. Since function.pageaddvar.php just calls PageUtil::addVar, This led me to suspect that the problem was with the template literals that contain
Code
</scr%ipt>
Then I tried to assign sth to a variable in the tpl file, like
Code
{assign var='sss' value='<scr%ipt type="text/javascript">alert("header");</scr%ipt>' }
The very existence of this assignment (even if I don't do anything with $sss) seems to confuse Smarty and cause the same problem I had with pageaddvar.
So how do i add raw js using pageaddvar?
Edited by xizhou on Sep 03, 2011 - 11:45 PM.
