Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty : evaluate a template stored in a PHP variable

Tags:

php

smarty

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

like image 301
Rami Dabain Avatar asked Nov 30 '10 14:11

Rami Dabain


1 Answers

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

like image 163
meze Avatar answered Nov 12 '22 07:11

meze