Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

page_add_script() does not work

#101

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);

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

State: invalid
Milestone: none
Assigned to: lux lux

Activity

  1. lux
    lux
    • 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...

    January 11th, 2009 @ 09:40 PM

  2. Vojtech Jina
    Vojtech Jina

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

    January 12th, 2009 @ 01:47 AM

  3. lux
    lux

    No worries, glad it works for you :)

    January 12th, 2009 @ 01:50 AM

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.