我一直在試圖展示一個智者模板一個PHP變量,但它是不可能的。顯示PHP變量上的Smarty模板3
在我的TPL我有:
<a href="#">Welcome <strong><!--{$username}--></strong></a>
在我的PHP我有:
<?php
require('../common/Smarty/config.php'); //Smarty Config Class
require_once('../common/config/config.php'); //Project Config Class
require_once('../common/classes/Login.php'); //Login Class
$smarty = new Smarty();
$template = "login.tpl";
$smarty->assign ("username", $user_name); //first: smarty variable, last: php variable.
$smarty->display ("{$template}");
?>
什麼即時試圖做的是太顯示用戶在登錄頁面的用戶名。
任何幫助?
在此先感謝。
BTW我使用<! - {和} - >爲Smarty的分隔符 – ccquir
在'$ smarty-> display(「{$ template}」);',smarty需要模板文件名或其他有效的模板資源。我認爲它不是最好的濫用HTML評論作爲聰明的分界。想象一下,你想在你的代碼實際使用HTML註釋,你可能會得到一個智者語法錯誤然後 – sofl
模板能否正常顯示,evrything罰款圖像和CSS,問題是試圖展示$ USER_NAME變量。實際上,如果我刪除:$ user_name,並添加「Peter」之類的內容,模板將顯示該名稱。 – ccquir