#101 ✓invalid
Vojtech Jina

page_add_script() does not work

Reported by Vojtech Jina | January 11th, 2009 @ 07:17 PM

When I use function page_add_script(), it does not work. It adds link to JS into $page->scripts array, that's right. But the problem is: When XT tpl is being parsed, $tpl->fill() function is called, it iterates all tags... So, it adds head tag before it run script of some application (box). It does not write output at this time, output is written at the end - by echo $response in index file. But the other head info, like metadatas, is added into $tpl->output at the time, that head tag is iterated.

Possible sollution (but not so nice sollution, in my opinion) would be: at the end of the fill function (obj XT), we should replace head by including css, js and head (replacing by datas from $page->scripts and so on)

something like:


$includes = implode("\n", $page->scripts);
$includes .= "\n</head>";
$this->output = str_replace('</head>', $includes, $this->output);

Comments and changes to this ticket

  • lux

    lux January 11th, 2009 @ 09:40 PM

    • State changed from “new” to “invalid”

    If the box is being called from inside the template that's already being parsed (e.g., with <xt:box />), then yes this will fail. You can pre-load things in a couple of ways though:

    • Boxed embedded in the page body can call page_add_script() since the page body is parsed first.
    • You can add an initialization routine that calls these to inc/conf/properties.php, which behaves the same as the conf/properties.php file for each app, but does so globally.
    • Add a myapp/init box call in the head of the template and load any scripts you need to for your app there.
    • Just load the scripts in place in the body of the page. There's no reason you can't load them in the body instead of the head, and that's actually encouraged for improving load times if you load whatever you can after the rest of the content so it all loads first for the user.

    For more info on that last point, see:

    http://developer.yahoo.com/perfo...

  • Vojtech Jina

    Vojtech Jina January 12th, 2009 @ 01:47 AM

    Sorry for invalid ticket, your sollution works fine. I didnt know it...

  • lux

    lux January 12th, 2009 @ 01:50 AM

    No worries, glad it works for you :)

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Sitellite web content management system.

People watching this ticket

Pages