1

我有文本存储在我的数据库中:

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 不会在变量中呈现变量。

有人能帮我吗?

4

2 回答 2

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

于 2013-11-07T12:19:31.647 回答
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);
于 2014-05-20T12:30:50.500 回答