Categories > TinyButStrong general >

Loading a template from a variable

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Julien
Date: 2005-09-09
Time: 09:41

Loading a template from a variable

Hi,
I'm not yet very used to TBS and i don't have too much  time so i learn little by little.
Sorry if this has already been addressed in this forum.

I need to load a template, not from a file, but from a variable as my templates are saved in a database.
So to go quicker, i've rewrite the LoadTemplate method to make a LoadTemplateFromVar method.

But as i seen, you guys have done a very good job in TBS and you seem to have thought a lot of things. I discover TBS is much more complete than i thought at first and i'm very pleased. So i begin to think that maybe you have a method to load a template from a var and maybe my method is obsolete. Can you confirm ?

Many many thanks.
Julien.
By: Skrol29
Date: 2005-09-09
Time: 09:50

Re: Loading a template from a variable

Hello,

Why can't you do:
  $TBS->LoadTemplate($myfile) ?
By: Julien
Date: 2005-09-09
Time: 10:16

Re: Loading a template from a variable

Hi skrol,

You are quicker than my shadow.

I cannot do this because, on my server, i don't have any file template.
My templates are stored in a database. So i get the content of the template from a record in the database.

I've tried to load the template as you said :
$TBS->LoadTemplate($myvar) but it doesn't work :
TinyButStrong Error (LoadTemplate Method): Unable to read the file '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>[var.transaction] [var.type_de_bien] Paris</TITLE> [...]

By: Skrol29
Date: 2005-09-09
Time: 10:20

Re: Loading a template from a variable

Ha, ok,

So the good way is:
$TBS->Source = $template_contents;
$TBS->MergeSpecial('onload');
By: Julien
Date: 2005-09-09
Time: 10:40

Re: Loading a template from a variable

Hi Skrol,
Ok thanks.

What is the purpose of the MergeSpecial method ? I've read the doc but cannot clearly understand why you advice me to do it.

If i do a $TBS->Show() later, do i need to do a $TBS->MergeSpecial('onload') before ? If yes, why ?
By: Skrol29
Date: 2005-09-09
Time: 10:47

Re: Loading a template from a variable

It enables you to merge automatic "onload" fields and blocks.
This is done with LoadTemplate(), but when you force the contents, you have to start this process manually.

Var fields and "onshow" will be merged automatically during Show().