Categories > TinyButStrong general >

Sub Templates

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Sebastian
Date: 2005-04-25
Time: 17:52

Sub Templates

Is it possible to include other php files as subtemplates which themselves use the tbs-class and merge it with a html template? According to your example [onload;file=[var.tmpl_article]]  and $tmpl_article = example.php.

Thanks

Sebastian
By: Skrol29
Date: 2005-04-25
Time: 18:21

Re: Sub Templates

Hi Sebastian,

It is possible and particulary simple since TBS 2.02.
New parameter 'subtpl' enables you to access the current TBS instance, and use it in a subtemplate mode. This means you can load an merge subtemplates as if they were normal templates. And the result is inserted in the main template.

You've got more details in the last version of the manual at chapter "Subtemplate".

Enjoy,
By: Sebastian
Date: 2005-05-04
Time: 21:51

Re: Sub Templates

Hi Skrol,

thanks for your answer. I tried to use this subtemplate functionality, but unfortunately did not succeed  :-((
I have looked at your examples but could not figure out why it did not work. Maybe I was not precise enough with my first question. I would like to use another php-script as a subtemplate which itself uses a separate html template (based on the tbs-class). Is this possible?

HTML: [var.file;script=specialbox.php;subtpl]

-> What if "specialbox.php" itself should execute a merge with the template "specialbox.htm" containting tbs-tags like [var.specialbox1]

PHP script: <?php
  echo('* Here include a subtemplate *');
  $this->LoadTemplate($CurrVal); // $CurrVal is a local variable provided by TBS
  $this->MergeBlock('blk1','SELECT * FROM table1');
  $this->Show();
?>


Thanks for your answer.

Sebastian
By: Skrol29
Date: 2005-05-05
Time: 02:25

Re: Sub Templates

Hi Sebastian,

There is a small error in the example of the manual.
Wrong line:
  $this->MergeBlock('blk1','SELECT * FROM table1');
Good line:
  $this->MergeBlock('blk1',$GLOBALS['conn_id'],'SELECT * FROM table1');

I've just changed this in the manual.
I've also tested this example, it works.
(Assuming you have correct connection and data).
By: Sebastian
Date: 2005-05-05
Time: 10:19

Re: Sub Templates

Hi Skrol,

could you just comment on the option to merge a html-template via a subtemplate php-script.



HTML: [var.file;script=specialbox.php;subtpl]

-> What if "specialbox.php" itself should execute a merge with the template "specialbox.htm" containting tbs-tags like [var.specialbox1]

PHP script: <?php
  echo('* Here include a subtemplate *');
  $this->LoadTemplate($CurrVal); // $CurrVal is a local variable provided by TBS

wouldn´t it be necessary to have something like
$this->LoadTemplate("specialbox.htm");


  $this->MergeBlock('blk1','SELECT * FROM table1');
  $this->Show();
?>
Thanks

Sebastian
By: Skrol29
Date: 2005-05-05
Time: 14:08

Re: Sub Templates

Hi Sebastian,

> could you just comment on the option to merge
> a html-template via a subtemplate php-script.

I'm not sure to understant what you'd like me to explain.

> What if "specialbox.php" itself should execute a merge with
> the template "specialbox.htm" containting tbs-tags like [var.specialbox1]

Parameter  'file' just includes a subtemplate in the main template by inserting text. This way, Var fields and [onshow] in the subtemplate are merged all the same on Show() of the main template.

But if you need some special Php code to drive the subtemplate insertion, then a script is needed. Use parameter 'script'. Parameter 'subtpl' precisely enables such a script to performe some LoadTemplate() and MergeBlock() for the subtemplate. 

> wouldn´t it be necessary to have something like
> $this->LoadTemplate("specialbox.htm");

  $this->LoadTemplate($CurrVal);
and
  $this->LoadTemplate("specialbox.htm");
are two ways for doing the same.
$CurrVal is a local variable that contains the value of the merged field.

The example assumes that the global variable $file contains the name of the template to load. If $file == 'specialbox.htm', then  [var.file;script=specialbox.php;subtpl] will run the script "specialbox.php" and in this script, $CurrVal == 'specialbox.htm'.


By: Pirjo Posio
Date: 2005-05-05
Time: 20:24

Re: Sub Templates

Would you Skrol29 please insert the last paragraph of your answer above into the TBS manual below the example spoken about? It helps to understand. Thanks!
By: Skrol29
Date: 2005-05-06
Time: 10:20

Re: Sub Templates

Ok, good idea.
Thanks for your comments.