Categories > TinyButStrong general >

[bug] script include doesn't work

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RwD
Date: 2005-05-04
Time: 20:12

[bug] script include doesn't work

I am rewriting a website that was using an older tbs version and I found a weird problem. I want to include a php script and for as far as I can tell from all documentation on this website this is the way with tbs 2.02: [onload; script=[var.dir.templ]news.php]
But it displays this instead of including the file "[onload; script=./../news.php]"

Other variables in the same template file do get merged so it isn't a protect setting. Any clue??
By: RwD
Date: 2005-05-04
Time: 20:28

Re: [bug] script include doesn't work

Got some more information.

First I load the main template, that includes a template which includes another template. This last template has the [onload] directive.
By: RwD
Date: 2005-05-04
Time: 20:40

Re: [bug] script include doesn't work

It seems to be like this. I include the second template using a MergeBlock statement so it is not included with the LoadTemplate() method. As it says in the manual the onload fields will only be merged with LoadTemplate() (Or mergespecial)

Anyway. This code was allmost unchanged from an older tbs version which did work. Perhaps you can have onload mean "on loading of the template (either by LoadTemplate or inclusion using file=)
By: Skrol29
Date: 2005-05-05
Time: 02:01

Re: [bug] script include doesn't work

Hi Rwd,

Can you give more info about the technic you used to perform the subtemplate inclusion ? It can help me to reproduce the bug.
Was the MergeBlock() statement merging a linked field containing a paremeter 'file', or 'script', ... ?
By: RwD
Date: 2005-05-05
Time: 08:48

Re: [bug] script include doesn't work

I made a testcase as small as I could get it:

index.php:
<?php
require( 'class-tbs.php' );
$tbs         = new clsTinyButStrong();

$tbs->LoadTemplate( 'page.htm' );
$tbs->MergeField( 'mainbox', '' );
$tbs->Show();
?>

page.htm:
[mainbox; file=box.htm]

box.htm:
[onload; script=test.php; getob]

test.php:
<?php
echo 'hello, test.php';
?>

And ofcourse include class-tbs.php in the same directory.
Then when you open index.php you get "[onload; script=test.php; getob]" rather then "hello, test.php" which I would have gotten in older tbs versions pre v2.

At the moment I am just using mergespecial to get the fields to load scripts anyway. but I think onload should mean "on loading this template"...
By: Skrol29
Date: 2005-05-05
Time: 14:53

Re: [bug] script include doesn't work

Hi RwD,

You're right.

Your template run as expected for TBS version 1.x with tags [tbs_include.onload]. But when you migrate to TBS 2.x and replace [tbs_include.onload] with [onload] (keeping the same parameters as said in the migration kit), then the tag [onload] placed in the subtemplate is not marged.

This is because the Show() method in TBS 1.x merges both [tbs_include.onload] and [tbs_include.onshow] tags. While it merges only [onshow] tags with TBS 2.x.

So you're right it's a kind of bug, or at least an undocumented behavior change. The more simple in your case is to replace
  [onload; script=test.php; getob]
by
  [onshow; script=test.php; getob]
It will be processed correctly.
By: RwD
Date: 2005-05-05
Time: 19:02

Re: [bug] script include doesn't work

But then the behaviour as it seems is not what the name suggests or at least, it wasn't. The name onload suggests that that specific part is executed when the template is loaded. onshow implicates the moment the template is shown (show method is called).

Can you, or rather would you change the behaviour to make onload mean "when the template is loaded"??
By: RwD
Date: 2005-05-05
Time: 19:11

Re: [bug] script include doesn't work

I tried your suggestion but I need to have the scripts included onload.

(TinyButStrong Error (Merge PHP global variables): Can't merge [var.PageCount] because there is no PHP global variable named 'PageCount'. This message can be cancelled using parameter 'noerr'.)

Onshow is too late as I merge some fields using variables declared in the included script. So now I am using a mergespecial for a field that imo should have been processed allready. But I am curious as to your explaination; perhaps I look at it from the wrong angle ;)
By: Skrol29
Date: 2005-05-05
Time: 19:34

Re: [bug] script include doesn't work

In TBS 1.x, the behavior was not the one suggested by the name [tbs_include.onload]: for flexibility, such tags were also merged on Show().

In TBS 2.x, the behavior is less flexible but more coherent: [onload] tags are merged only on LoadTemplate().

After what we've with this problem, I'll will thing to see if it's interesting to process [onload] fields after a 'file' inclusion. The concern is that it's maybe  too expensive in term of time execution.

BTW: I'm sure that in your case the [tbs_include.onload] was not merged when the parent field is merged, but on Show(). You can notice it by yourself using your script by replacing:
   $TBS->Show();
with:
   echo $TBS->Source;
 
By: RwD
Date: 2005-05-05
Time: 22:13

Re: [bug] script include doesn't work

Don't know, I am done converting the site to tbs 2.x. The thing I know is that it did work the way it was with tbs 1.95. Aah well, this is going to be some yes-no game. I just hope performance does not go down by using onload on loading the file.

Else oninclude ;)