Categories > TinyButStrong general >

subtemplate problem

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Greg
Date: 2005-06-03
Time: 20:20

subtemplate problem

Hi All,

Maybe someone can help.

I have two php files, one header.php and the other footer.php. I have a html file that is to get sandwiched between the php files.

My problem is I cannot seem to get all the elements to work together. I only get variations.

Here is what I tried...

I have a template file named template.htm with the following code:

[onload;script=header.php]
[onload;script=[var.response]]
[onload;script=footer.php]

The php code is:

include_once('classes/tbs_class.php');
$response = "responses/body.htm";
$template = "responses/template.htm";
$tpl = new clsTinyButStrong;
$tpl->LoadTemplate($template);
$tpl->Show();

Any help is greatly appreciated.

Thanks,
Greg
By: Skrol29
Date: 2005-06-03
Time: 21:55

Re: subtemplate problem

Hi greg,

I think your "template.htm" should be:
[onload;script=header.php]
[onload;file=[var.response]]
[onload;script=footer.php]

The difference is that "body.htm" is not a Php script.
By: Greg
Date: 2005-06-03
Time: 23:31

Re: subtemplate problem

Skrol29,

Thanks for the reply.

I changed it as you showed and all I am getting is the header and footer.

Greg
By: Skrol29
Date: 2005-06-04
Time: 01:26

Re: subtemplate problem

Ok sorry, there where anothing thing.

Your template should be:
[onload;script=header.php;getob]
[onload;file=[var.response]]
[onload;script=footer.php;getob]

or if you have TBS 2.02.x:
[onload;script=header.php;subtpl]
[onload;file=[var.response]]
[onload;script=footer.php;subtpl]

By default, parameter script run the script has is. This means the echo() command displays strings immediatly to client, not inside the template. You have to use a special parameter to indicate that you want the string to be output inside the template.

Enjoy,
By: Greg
Date: 2005-06-04
Time: 02:29

Re: subtemplate problem

Skrol29,

I tried both and still no go.

I have 2.02.x

When I use "subtpl" I just get just the footer.

Greg
By: Pirjo Posio
Date: 2005-06-04
Time: 08:50

Re: subtemplate problem

Hi Greg,

All this is correct, what SKrol29 told you. But you still probably have one problem in your subtemplates, header and footer.php:
Here's the model for subtemplates in the TBS manual:
<?php
  echo('* Here include a subtemplate *');
  $this->LoadTemplate($CurrVal);
  $this->MergeBlock('blk1',$GLOBALS['conn_id'],'SELECT * FROM table1');
  $this->Show();
?>

As you can see, you should use $this in the subtemplates instead of $TBS.
By: Pirjo Posio
Date: 2005-06-04
Time: 08:54

Re: subtemplate problem

For Skrol29:
Come to think of it, maybe you should in the above example in the manual instead of "Here include a subtemplate" write "This is the subtemplate" to make it clearer.
By: Skrol29
Date: 2005-06-06
Time: 00:28

Re: subtemplate problem

I agree with Pirjo, the problem probably comes from you scripts. They probably do something special.
By: Greg
Date: 2005-06-08
Time: 16:24

Re: subtemplate problem

Hi Pirjo and Skrol29,

Thanks again for the help.

The header.php is nothing more than HTML and the footer is HTML with a db close connection code.

In the [onload;file=[var.response]] file their is one variable.

Right now submiting it with your suggestions, only returns the footer.

One question, echo('* Here include a subtemplate *'); on this line, is this just text or this it for the pointer to the file itself?

Thanks,
Greg
By: Skrol29
Date: 2005-06-08
Time: 19:36

Re: subtemplate problem

Could you send your files, so I can have a deeper look.
By: Greg
Date: 2005-06-08
Time: 19:49

Re: subtemplate problem

Sent via email.

Thanks,
Greg
By: Skrol29
Date: 2005-06-08
Time: 22:17

Re: subtemplate problem

Ok, thanks for your files Greg.

Your "footer.php" script contains an "exit" Php command.
That's the problem.
TBS hasn't finished its job when the footer is insterted.
This is more true if you put the script using an [onload] tag. Such tags are processed just when the template is loaded. An exit command there will prevent TBS to execute any following command like $TBS->Show().
What is prompted then is what PHP had in its buffer at this time.

Just take off the "exit" command and it will run better.

Another thing: the "footer.php' script also contains a line to close the current database connection. This is also wrong to have it in a [onload] tag. It will close the connection while you still need it for following merging.
You could put it in a [onshow] tag, but the rigth place for such a code is in the PHP side.
Like this:
  $TBS->LoadTemplate(...); // Load the template
  ...
  $TBS->MergeBlock(...); // Merge some data with SQL
  if(isset($db)) $db->CloseConnection(); // Close the database connection
  $TBS->Show(); // Automatic ending merges and display result
 


By: Greg
Date: 2005-06-09
Time: 12:26

Re: subtemplate problem

Skrol29,

That did the trick.

Thanks again.

Greg