tags:

views:

17

answers:

1

Hi All

I'm sending one of my object to smarty like

$smarty->assign('test', new MyObject ) ;
....
$smarty->display('main.tpl');

the MyObject class has a function called 'render' which returns a string representation of itself.

So in main.tpl I want to render this object like

{$test->render()}

Unfortunately it doesn't show anything in the HTML. Any suggestions how I can make this work ?

Thnx a lot Jeanluca

+1  A: 

You need to use $smarty->register_object().

Reference: Smarty features: Objects

Pekka
Thats what I need, thnx!I just noticed that my code does work. Is register_object the preferred way when dealing with object?
Jeanluca Scaljeri
@Jeanluca I don't know whether `register_object()` is better or worse than `assign_by_ref()`. In PHP 5, they shouldn't make a difference anyway (because object arguments get automatically passed by reference). If you want to make sure, for *huge* objects, maybe use `assign_by_ref()`.
Pekka