Smarty : evaluate a template stored in a PHP variable

Rami Dabain picture Rami Dabain · Nov 30, 2010 · Viewed 8.7k times · Source

i have a php variable which has html/smarty code in it

$x='<a href="{$link}" >{$title}</a>';

This data is fetched from database , i want to evaluate it using smarty and put the output into a php variable (to print it out or to save it to the database again) .

Thanks

Edit :

i want the content of X to be evaluated using smarty , as if the content of x is stored in a file.tpl then $y=$smarty->fetch('file.tpl'); ... want to do it without the need to save the content of x into a file

Answer

meze picture meze · Nov 30, 2010

If you're using Smarty 3, you can easily do it by

$smarty->fetch('string:'.$template_string);

or 'eval:'.$template_string. more about it in the manual