Categories > OpenTBS with ODT >

Multiple documents from one template in a loop

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: om
Date: 2013-03-13
Time: 23:31

Multiple documents from one template in a loop

I would like to print multiple documents from a single template, with each document containing different data.  Basically loop through some array using a single template.  My expectation was that I could do this and then get multiple files to open -- but instead I get only the data from the first run through the loop.  Here's an example:

<?php
include_once('../tbs/tbs_class.php');
include_once('../tbs/tbs_plugin_opentbs.php');

$count=0;
while ($count<=2) {
  $TBS = new clsTinyButStrong;
  $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

  $template="../templates/test.odt";
  $TBS->LoadTemplate($template);
       
  // Define the name of the output file
  $fileName="test_$count.odt";
           
  // download
  $TBS->Show(OPENTBS_DOWNLOAD, $fileName);

  $count++;
}
?>

text of my template named test.odt:

Simple Example

Variable:  [onshow.count]

So what I expected was three documents named test_0.odt, test_1.odt, test_2.odt with the numbers 0,1,2 in the document respectively.  What I get is just test_0.odt with the number 0 in the document.

Is there a way to do this -- generate multiple documents from one template using a loop?
By: Skrol29
Date: 2013-03-15
Time: 00:43

Re: Multiple documents from one template in a loop

Hi OM,

Your loop is good except that your browser can do only one download.
When you are using OPENTBS_DOWNLOAD, then OpenTBS exit the script. You can avoid this, but a secondary download will only make errors in the headers and in the binary contents.
You have to use OPENTBS_FILE instead.
By: anagama
Date: 2013-03-15
Time: 18:39

Re: Multiple documents from one template in a loop

Awesome -- thanks for the hint.  I made the suggested modification, added a line to link to the files -- works great:
<?php
include_once('../tbs/tbs_class.php');
include_once('../tbs/tbs_plugin_opentbs.php');

$count=0;
while ($count<=2) {
  $TBS = new clsTinyButStrong;
  $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

  $template="../templates/test.odt";
  $TBS->LoadTemplate($template);
 
  // Define the name of the output file
  $fileName="tmp/test_$count.odt";
  
  // download
  $TBS->Show(OPENTBS_FILE, $fileName);

  print "<a href=\"$fileName\">$fileName</a><br>";

  $count++;
}
?>
By: Kim
Date: 2015-08-24
Time: 15:48

Re: Multiple documents from one template in a loop

Can these multiple documents be merged into one download?