[英]Smarty Template Variable inside Variable
我將文本存儲在數據庫中:
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無法在變量內部呈現變量。
有人能幫我嗎?
你可以這樣做
$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
或者,如果您使用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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.