By: RwD
Date: 2005-05-04
Time: 16:28
|
subtpl, what does it do
I am wondering what the variabe subtpl does exactly. Wasn't I allready able to include subtemplates??
Or can this solve my problem:
I have a 2d array:
[1] {
[name] = 'test'
[value] = '123' }
[2] {
[name] = 'try'
[value] = '456' }
[3] {
[name] = 'trial'
[value] = '789' } |
But for this array the keynames are variable and it can also be more keys then just 'name' and 'value'. I want to generate a table with as many columns as needed (and a row for each entry ofcourse)
Probably you will suggest sub-blocks like in the examples. But it would be cool if subtpl could help me I think...
|
By: Skrol29
Date: 2005-05-04
Time: 16:42
|
Re: subtpl, what does it do
Hi Rwd,
I don't think parameter 'subtpl' can help you on this.
Technically, parameter 'subtpl' tunes the current instance of TBS to be used for another template (subtemplate) and then returns automatically into the previous setting. It also catches outputs to insert them at the tag place's, just like parameter 'getob'.
For your problem, do you know the list of possible columns?
If you know it before the merge, then you can place all columns, and corresponding TBS fields with parameter 'noerr'.
If you don't know it, can't you just read the data a first time in order to get the list of all possible columns, and then perform a dynamic columns table like in the example?
|
By: RwD
Date: 2005-05-04
Time: 17:45
|
Re: subtpl, what does it do
Then what is the difference with getob? Why not kept the same name for templates as well?
On the problem:
No, it can be absolutely anything and any number of columns
|
By: Skrol29
Date: 2005-05-04
Time: 18:18
|
Re: subtpl, what does it do
The difference with 'getob' is that 'subtpl' gives access to a $TBS local variable which has the same markers, same HtmlCharSet and an empty contents. I will provide an example with the Example Set.
template:
[var.subtemplate;script=subscript.php;subtpl]
|
subscript.php:
$TBS->LoadTemplate($CurrVal);
$TBS->MergeBlock('subblock',...);
$TBS->Show();
|
$TBS and $CurrVal are local variables provided by TinyButStrong.
In fact, variable $TBS is the same instance as the main template, so it's optimized. But most of all, coding for subtemplate becomes very simple.
On your problem, the second solution I indicated seems to be the good one.
|
By: Skrol29
Date: 2005-05-05
Time: 02:04
|
Re: subtpl, what does it do
Sorry: replace variable $TBS with variable $this in my previous message.
$TBS is provided when parameter 'subtpl' is used with a custom function, not a script.
|
By: RwD
Date: 2005-05-06
Time: 16:52
|
Re: subtpl, what does it do
I got 5 minutes today to work on the problem, and I cracked the case. It was really easy actually. Lets see if you agree with my solution.
So the problem was that I wanted to list the contents of a database table on the screen using an html table. But this table had an unknown number of columns and rows so no dimensions are known.
To solve it I remembered that tbs uses the source to scan for locator fields whenever it needs to perform any action on it. So I got the idea to just simplyhave the template be turned into another template using tbs (or that is the idea behind this at least). Enough talk, here is the thing I did:
template: <table>
<tr>
<td>[values.[keynames.name;block=td]; block=tr]</td>
</tr>
</table> |
As you can see this is a one cell table, which will not hold a lot of data. but it has only one valid tbs locator inside. If it is merged with simple data a new valid tbs locator appears :)
So to make this work you only need to merge correctly, and since I am using an database object I used the following php: $DB->query( 'select * from users' );
$DB->first_record();
// Build an array with the keynames
foreach( $DB->Record as $key => $value ) {
$new_columns[]['name'] = $key;
}
// Build an array with the data
$rows[] = $DB->Record;
while( $DB->next_record() ) {
$rows[] = $DB->Record;
}
// Merge so columns appear
$tbs->MergeBlock( 'keynames', 'array', $new_columns );
// Merge the data
$tbs->MergeBlock( 'values', 'array', $rows ); |
Perhaps tbs could use a "tips & tricks" section where tricks can be shared. If they are ordered in categories that could be very very usefull!!
Perhaps they could be ordened as your examples page is so everybody can see working examples, templates and scipts???
|
By: Skrol29
Date: 2005-05-06
Time: 17:37
|
Re: subtpl, what does it do
Your solution is good. But it's a simplification of the Dynamic Column issue posted in the forum "Tip and Trick".
|
By: RwD
Date: 2005-05-09
Time: 12:21
|
Re: subtpl, what does it do
I knew I had seen tips & tricks somewhere on this website allready. Kind of stupid I didn't see it while posting that last post. I'll check out your dynamic comlumns solution to see how you did alternating column display as that wasd going to be my next thing to figure out ;)
Thanks
btw, wouldn't you like a tips & tricks section that is alike the examples page?
|
By: Skrol29
Date: 2005-05-09
Time: 20:54
|
Re: subtpl, what does it do
> btw, wouldn't you like a tips & tricks section that is alike the examples page?
Yes it would be nice, but it's a lot of work.
|
|
Posting in progress.
Please wait...
|