Categories > TinyButStrong general >

Can TBS build two templates at once?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Don Bledsoe
Date: 2007-05-22
Time: 20:15

Can TBS build two templates at once?

I'm not sure how to go about doing this, but this is what I want to do:

I have an application that tracks my customers' domain registrations. It sends them an email notification that their registration will soon be expiring.

Here's what I want to do --

Read the MySQL and determine if any domains will expire in <31 days. Possible results are: 0, 1, >1

In preparing this, I will need to build an email template. This is done and works correctly.

BUT -- I also want to display the results on the screen, so I want to build two templates simultaneously ... one to display what is happening and the other to build an email for each record found.

I imagine that TBS can do this, I just don't know how to go about it.

In preparing the email template, I use:
$TBS->LoadTemplate('includes/emailnotice.tpl.html');
$TBS->MergeBlock('blk','tbssql','SELECT statement...');
$messageBody = $TBS->Show(TBS_OUTPUT);
Is this correct?

I think I can prepare the two templates using something like this:
$TBS->MergeBlock('blk1,blk2','tbssql','SELECT * FROM MyTable');
Do I have the right idea? How does one load two templates at the same time?

The only other issue I see if that I need to send an email for each record found (1 or >1) but I see the danger that possibly all records would be dumped into a single email, so I'm looking to avoid that possibility as I get this to work.

I can use any suggestions and recommendations on how to best solve this problem.
By: Skrol29
Date: 2007-05-23
Time: 00:20

Re: Can TBS build two templates at once?

Hi Don,

> $messageBody = $TBS->Show(TBS_OUTPUT);

This is no correct. It display the result of the merge, but do not save it into $messageBody. You have to do:
$TBS->Show(TBS_OUTPUT);
$messageBody = $TBS->Source;

If you already know that you may have several domains to merge, then it is better to save the domains into an array, and then merge domaines one by one.
Example :
$Data = $Db->GetRows('SELECT statement...');
$TBS->LoadTemplate('includes/emailnotice.tpl.html');
$Src = $TBS->Source;
foreach ($Data as $dom) {
  $TBS->MergeBlock('blk',$dom);
  $messageBody = $TBS->Source; // save the result
  echo $messageBody; // display result
  email(...,...,$messageBody); // send email
  $TBS->Source = $Src; // restore template
}

But i you want to play with several templates (one for email body, and one for admin interface), then it is better to use 2 TBS instances, and merges different parts of the two templates using the same data ($Data).