Categories > TinyButStrong general >

Added functionality

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RwD
Date: 2006-03-15
Time: 13:47

Added functionality

I am rebuilding a system I made and I am transforming more and more to be more object oriented. While doing that I ran into the problem of some variable not being available in subtemplates. I came up with a solution which works for my specific setup.

I added the following to the clsTinyButStrong class:
// Extra data passed by for example the vatage mailer to bypass the "variable globals" problem.
// By passing data here in any template [var.tbs.Data.Name] will be available
var $Data = array();

/**
* Add data to the tbs object which is used to merge with a template
*/
function loadData($newData) {
    if ( is_array($newData) ) {
        foreach( $newData as $key => $value ) {
            $this->Data[$key] = $value;
        }
    }
}

Then in subtemplates I can allways use [var.tbs.Data.key] and get the data in.

Would this be a bad solution? Is there a better one?
By: Skrol29
Date: 2006-03-15
Time: 18:20

Re: Added functionality

Hello RwD,

You can already do the same using $TBS->TplVars.
Example:
$TBS->TplVars['data'] = $newData;
In the template:
[var..tplvars.data.key]
By: RwD
Date: 2006-03-17
Time: 11:41

Re: Added functionality

Great, how do I set those?
By: Skrol29
Date: 2006-03-17
Time: 12:43

Re: Added functionality

Just like I did. (I'm not sure to well understant your question).
TplVars is a native property of TBS. In subtpl Mode, you can have it throught $this->TplVars.
By: RwD
Date: 2006-03-22
Time: 10:16

Re: Added functionality

Am I not in danger of overwriting existing information that tbs might need or anything else when just writing to TplVars?

Should there not be a function to handle this?
By: Skrol29
Date: 2006-03-22
Time: 10:40

Re: Added functionality

No danger. TplVars contains only user data stored manually or using parameter "tplvars". This feature is just a hook made for the purpose you described.
By: RwD
Date: 2006-03-22
Time: 11:24

Re: Added functionality

Should you not add a function to load data to it? One in the form I showed? It saves me from having to check each and every time if data needs to be loaded.

As a workaround I made a template engine wrapper that extends tbs and adds the functionality...
By: Skrol29
Date: 2006-03-23
Time: 01:10

Re: Added functionality

Cound't it be done using a simple array_merge() or something similar ?

In first study, I found this feature very specific. Plug-ins (coming soon) should enable you to make such customization.