我的文本存储在我的数据库中:
Your email is: {$email} and your name is {$name}.
$text = get from db this field;
我从数据库中读取了这个字段
我聪明地指定了这个:
$smarty->assign('text', $text);
$smarty->assign($name, 'maria');
$smarty->assign($email, 'maria@email.it');
并在我的html页面中用以下内容进行可视化:
{$text}
结果是:
Your email is: {$email} and your name is {$name}.
我的问题是Smarty没有在变量中呈现变量。
有人可以帮助我吗?
答案 0 :(得分:1)
你可以这样做
$smarty->assign('name', 'maria');
$smarty->assign('email', 'maria@email.it');
$smarty->assign('text',$smarty->fetch('string:'.$text));
查看http://www.smarty.net/docs/en/resources.string.tpl了解详情
修改强>
如果您将模板存储在数据库中,我建议您阅读自定义模板资源 http://www.smarty.net/docs/en/resources.custom.tpl
答案 1 :(得分:1)
或者如果你使用Smarty 2
$template = "Your email is: {$email} and your name is {$name}."
require_once( $smarty->_get_plugin_filepath( 'function', 'eval' ));
$smarty->assign('name', 'maria');
$smarty->assign('email', 'maria@email.it');
$compiled = smarty_function_eval(array('var'=>$template), $smarty);