Categories > TinyButStrong general >

How to show?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jesus
Date: 2006-12-20
Time: 19:13

How to show?

I read the documentation and I do not include/understand like showing a simple function that receives several parameters…

In the documentation
[var.arr.item1]             will display             $arr['item1']
[var.arr.item2.a.0]           will display           $arr['item2']['a'][0]
[var.obj.prop1]           will display           $obj->prop1
[var.obj.methA]           will display           $obj->methA()
[var.obj.methB(x,y)]           will display           $obj->methB('x','y')
ok work fine!
But, how to Show myFunction in the template..???...!!!
Help please
function myFunction($p1, $p2) {
    $full_name = $p1." ".$p2;
    return $full_name;
}

By: Skrol29
Date: 2006-12-20
Time: 20:14

Re: How to show?

Hi,

You cannot do that.
The fist good reason is for security. The template should not be able to call any PHP things. Only things allowed are at least prepared for the template.

The other things is that some facilities are given to code expressions in the template, but we have to keep in mind that complicated expressions or evaluations should be made at the PHP side. The tag system of the Template Engine should not reach the level of another language.
By: TomH
Date: 2006-12-20
Time: 20:21

Re: How to show?

First, if you use your function just once to create $full_name (not several records from database) then simply use
[var.full_name]

Or, if you are getting multiple records with p1 and p2 fields from database and will repeat blocks with $full_name -  the php code
$TBS->MergeBlock('b1',$db_array) ;
$TBS->Show() ;

function myFunction($BlockName,&$CurrRec,$RecNum)) {
$CurrRec['full_name'] = $CurrRec['p1']." ".$CurrRec['p2'];
}

And in your HTML template
<tr>     [b1.full_name;block=tr;ondata=myFunction]  </tr>

This is NOT tested - but with this and the TBS Examples for "Event Functions" it should get you started

Hope that helps,