Forum Moderators: coopster

Message Too Old, No Replies

May be somebody can explain me how i can call a function in Smarty?

         

orion_rus

10:26 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



Hello world i have a template and i need to put a result of some function to it, how i can do it?
....
$smarty->assign('content',SomeFunction());
$smarty->display('index.tpl');
doesn't work((
Thanks in advance!

Elijah

3:10 am on Feb 22, 2005 (gmt 0)

10+ Year Member



Are you sure that SomeFunction() returns data?
To make sure try:

<?php
echo SomeFunction();
?>

That should help you narrow down the problem.

orion_rus

9:36 am on Feb 22, 2005 (gmt 0)

10+ Year Member



No function didn't returns data
Syntax of Somefunction is following:
<?
function Somefunction()
{?>
<table>
<tr>
<td>
hi
</td>
</tr>
</table>
<?
}
?>
is it allowing to make such function works in Smarty?

Elijah

1:01 pm on Feb 22, 2005 (gmt 0)

10+ Year Member



To pass data to a function you need to have the data in a PHP variable:
Try this:

<?php
function Somefunction()
{
$my_data = '<table>';
$my_data .= '<tr>';
$my_data .= '<td>';
$my_data .= 'hi';
$my_data .= '</td>';
$my_data .= '</tr>';
$my_data .= '</table>';
return $my_data;
}
?>

Now you function will be returning data which can be passed to Smarty.

orion_rus

1:58 pm on Feb 22, 2005 (gmt 0)

10+ Year Member



Thank you very much for help!