Categories > TinyButStrong general >

I can not run a php function in a template using tbs

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: fxaran
Date: 2011-04-27
Time: 20:58

I can not run a php function in a template using tbs

I need is to call a php function from a template.

I'm doing an experiment with this this function

My code:

This is the function

miFuncion.php
<?php

    function mostrarSuma($x,$y){
        echo $x * $y;
    }

?>


This is my driver:

pantalla.php

<?php
include_once '../librerias/tbs_class.php';
include_once 'miFuncion.php';

$sum = mostrarSuma();

$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('pantalla.tpl');
$TBS->Show();
?>

This is my template:

pantalla.tpl
<html>
<head>
<title>Insert title here</title>
</head>
<body>
The sum is: [var.sum]
</body>
</html>

From the template, how to define the parameters necessary for the function.?
By: Skrol29
Date: 2011-04-28
Time: 00:31

Re: I can not run a php function in a template using tbs

I'm not sure to understand.
You need to place a "x" value and a "y" value in the template and retrieve them for your $sum = mostrarSuma(x, y) ?
By: fxaran
Date: 2011-04-28
Time: 14:50

Re: I can not run a php function in a template using tbs

Now if I worked

My code:


return the sum variable

pantalla.php
<?php

    function mostrarSuma($i,$j){
        $r = $i * $j;
        return $r;
    }

?>


I give the parameters to call the function "mostrarSuma"

pantalla.php
<?php
include_once '../librerias/tbs_class.php';
include_once 'miFuncion.php';
$s1 = mostrarSuma(4,4);
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('pantalla.tpl');
$TBS->Show();
?>


And the template I call caught him in this way

pantalla.tpl
<html>
<head>
<title>Insert title here</title>
</head>
<body>
La suma es [var.s1]
</body>
</html>


By: fxaran
Date: 2011-04-28
Time: 15:15

Re: I can not run a php function in a template using tbs

now what I want is this...
put html code in php function that displays the template

for example

pantalla.php

<?php

    function mostrarSuma($i,$j){
        $r = $i * $j;
        echo "<table border=1 cellpadding=0 cellspacing=0>
            <tr>
                <td bgcolor=#FFFFFF>".$r."</td>
            </tr>
        </table>";       
           
    }

?>

The problem is this result
the template


4

TinyButStrong Error (Merge PHP global variables): Can't merge [var.s1] because there is no PHP global variable named 's1'. This message can be cancelled using parameter 'noerr'.
La suma es [var.s1]
By: Skrol29
Date: 2011-04-28
Time: 22:08

Re: I can not run a php function in a template using tbs

Hi,

In your first snippet, mostrarSuma() is a function that returns a result.
Despite in the second snippet, mostrarSuma() is a function that return nothing. Then $s1 gets the value null, which is PHP is the same as a non defined variable.
Alos, this function displays a text using echo(), which makes this text to be immediately displayed to the client, even before TBS can display its result.

By: fxaran
Date: 2011-04-29
Time: 19:59

Re: I can not run a php function in a template using tbs

thanks for the comment, I had noticed. If correct, if I include an echo, the echo will show me first before tbs