By: worchyld
Date: 2004-06-24
Time: 18:03
|
Running TBS via PHP Functions
I'm a newbie with TBS, but I've made my template and got it to run pretty well, however whenever I try to put the functionality of TBS into a PHP function it gives me the template file and doesn't replace the variable names.
For example,
my html template is:
<html>
<body>
[var.message]
</body>
</html>
|
And the launcher is;
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$templatesDirectory = $DOCUMENT_ROOT.'/templates/';
include_once('../class.tinybutstrong.php');
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate($templatesDirectory.'sendusernotification.htm');
$message = "hello world";
$TBS->Show();
|
This code works well. However as soon as I put it into a function, it doesn't work.
test();
function test() {
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$templatesDirectory = $DOCUMENT_ROOT.'/templates/';
include_once('../class.tinybutstrong.php');
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate($templatesDirectory.'sendusernotification.htm');
$message = "hello world";
$TBS->Show();
} // end function
|
I really need TBS in a function for a few things. Has anybody solved this problem? I hope you can help!
|
By: Skrol29
Date: 2004-06-24
Time: 18:12
|
Re: Running TBS via PHP Functions
Hi Worchyld,
This problem is known and should be fixed with next version 1.97 which is comming in very few days (I'm working on the documentation).
The problem is that TBS uses global variables which are defined at the beginning of the code this way:
$tbs_OpenChar = "[";
And which should be defined this way:
$GLOBALS['tbs_OpenChar'] = "[";
|
By: worchyld
Date: 2004-06-25
Time: 15:39
|
Re: Running TBS via PHP Functions
That's great to hear. I look forward to the update.
There's something else as well. I am using TBS for templating an email message (HTML based) and I realised that there isn't a function to store the outputted data into a php variable.
Hence, is it possible to add a function called 'Keep()' which is exactly like Show()?
In my keep() function, it doesn't echoing the output, it simply returns it so I can use it whenever I want, like in the output of an email message.
ie;
...normal setup of TBS goes here..
$email_body = $TBS->Keep();
...perform php email function...
|
|
By: Skrol29
Date: 2004-06-25
Time: 15:46
|
Re: Running TBS via PHP Functions
Hi,
The property Render enables you to tune the Show() method's behavior. You can have it not exiting and not outputing.
And at any time you can get the current result of the merge using property Source.
Enjoy,
|
By: halinux
Date: 2004-06-28
Time: 09:08
|
Re: Running TBS via PHP Functions
My solution:
funtion myFunction() {
$t = array();
$t['message'] = 'Hello world';
$t['myarray'] = 'array(1, 2, 3, 4);
return $t;
{
extract(myFunction() );
$tbs->LoadTemplate("template1.html");
-So, you put everything in an array in the fucntion, what you want to display.
-Return this array
-and with the extract function, create from this the variables.
e.g.: $message, $myarray
-and you can display it normally
e.g: [var.message] in the template1.html
Adam
|
By: worchyld
Date: 2004-06-29
Time: 11:23
|
Re: Running TBS via PHP Functions
Hey thanks alot for that. I'll try that idea out.
In my previous question I raised the point of just returning the outputted data rather than just showing it. The reply I got talked about using render. I've been playing around with render but I do not understand how to use it very well as I am just a newbie.
Can someone give an example of how to use render in the case of using it for an outgoing email message?
Many thanks.
|
By: Skrol29
Date: 2004-06-29
Time: 14:48
|
Re: Running TBS via PHP Functions
Example:
$TBS->LoadTemplate('message.htm');
...
$TBS->Render = TBS_NOTHING;
$TBS->Show(); //No output, no exit
$message = $TBS->Source;
|
|
By: worchyld
Date: 2004-06-29
Time: 15:10
|
Re: Running TBS via PHP Functions
No wonder I was getting it wrong.
Thanks a lot!
|
|
Posting in progress.
Please wait...
|