Categories > TinyButStrong general >

multiple templates in 1 file?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Tom
Date: 2006-11-09
Time: 16:32

multiple templates in 1 file?

I'm currently using patTemplate. I'm considering switching to TBS, but there is already one thing which I like in patTemplate and don't find in TBS, namelijk storing  multiple templates in 1 file

I like to keep my logic for one process (like registering== show form, save data, show succeed message) in 1 PHP file, and the templates for it in 1 template file. So I have at least 2 seperate templates in 1 file (one to show the form, one to show the succeeded message without the form). If the process is a multi-step process, I even have more. Is that possible in TBS or should all tempaltes be loaded from seperate pages?

By: Tom
Date: 2006-11-09
Time: 17:01

Re: multiple templates in 1 file?

I found another thing I like in patTemplate but I'm not sure is possible in TBS, namely adding multiple objects to one row.

sometimes one would have a row like this

<tr><td>person.first name</td><td>company.name</td></tr>

now I have something like this

$persons = fetchAllPersons();
foreach ($persons as $person) {

   $company = fetchCompanyOfPerson($person->id);
   $patTemplate->addObject('row', $person);
   $patTemplate->addObject('row', $company);
   $patTemplate->parseTemplate('row', 'a');

}

For TBS, I'd have to store all values of person in $row[], same for company and then after the whole loop do $tbs->MergeBlock. That causes all data to be duplicated & code to be less clear ...

$persons = fetchAllPersons();
foreach ($persons as $person) {

   $company = fetchCompanyOfPerson($person->id);
  
   foreach (array_keys($persons) as $key) {
      $row[$key]=$person->$key;
   }
   foreach (array_keys($company) as $key) {
      $row[$key]=$company->$key;
   }

   $rows[] = $row;
   unset($row);
}

$tbs->MergeBlock('row', $rows);

am I missing something? This seems so cluttered.
By: Skrol29
Date: 2006-11-11
Time: 03:52

Re: multiple templates in 1 file?

Hi,

Yes TBS can do both of you problems easily.

1)
You can do this with conditional sections. They are magic. I use them often to have the same template showing different steps for the user process. Or to save error warning messages about an HTML form.
Have a look at the online Examples. "Conditional display" and "Enter data in a form" are small but give the idea of what can be done.

2)
MergeBlock() can deal with an array of objects (since TBS 3.0.6).
[p.name;block=tr] ... [p.id] ...
$TBS->MergeBlock('p',fetchAllPersons());

For the company, it is given when you know the person id. So the more simple is to use a ondata function:
[p.name;block=tr;ondata=f_person] ... [p.id] ... [p.comp.name]
function f_person ($BlockName,&$CurrRec,$NumRec) {
  $CurrRec->comp = fetchCompanyOfPerson($CurrRec->id);
}
By: Tom
Date: 2006-11-11
Time: 16:40

Re: multiple templates in 1 file?

is it me or is <option value="x">[var.blk_id;ope=html;select]</option> undocummented in themanual ? I don't see ope=html there, it's not in the list of ope's options...
By: Skrol29
Date: 2006-11-11
Time: 16:56

Re: multiple templates in 1 file?

"ope=html" is supported since you've installed the HTML plug-in.
It is part of the HTML plug-in feature.