Fork me on GitHub

trouble in adding header js with plugin function.pageaddvar.php  Bottom

  • I was experimenting with Zikula 1.3, candidate 6.
    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.
  • Quote

    I was experimenting with Zikula 1.3, candidate 6.

    why are you using the RC when the actual release is available?
  • Sorry, the version i'm using is build 3168 which is what you get by clicking "Try Zikula 1.3.0!" I confused it with RC 6.

    Can anyone confirm that function.pageaddvar.php in build 3168 actually adds raw js to DOM headers correctly? I'm unable to get it work on separate installations of 3168 on two different computers.

    BTW I like the Zikula_UI tools but I'm having a hard time getting them work in IE 8 - if you put them in block js in the DOM like in the demos it'll cause a fatal error in ie8. This is because Control.Window creates elements and appends them to document body, and ie8 doesn't like you appending elements to the document body before it sees the closing tag

    Code

    </body>
    I'm forced to move most Zikula.UI instances to the header and load them with

    Code

    document.observe('dom:loaded' ..
    That's why I need the pageaddvar utility for the purpose of adding raw js so badly.
  • Have you tried the following?

    Code

    {pageaddvarblock name='header'}
    <script type="text/javascript"> YOUR SCRIPT HERE </script>
    {/pageaddvarblock}


    --
    - Mateo T. -
    Mis principios... son mis fines
  • Thanks Mateo. pageaddvarblock works.
    However I still don't understand why pageaddvar doesn't. If you can reproduce my problem, I think there's a bug in Zikula_View worth filing, most likely in a plugin that handles scripts. Just add the following to a tpl file

    Code

    {pageaddvar name='header' value='<scr%ipt type="text/javascript">alert("hello!")</scr%ipt>'}


    and load the page. "hello!" may or may not pop up on page loading, but the script doesn't render correctly and ruins the whole page, at least in my installations.

    nestormateo

    Have you tried the following?

    Code

    {pageaddvarblock name='header'}
     YOUR SCRIPT HERE
    {/pageaddvarblock}




    Edited by xizhou on Sep 06, 2011 - 11:18 AM.
  • 0 users

This list is based on users active over the last 60 minutes.