在Smarty模板3上显示php变量
我一直试图在smarty模板上显示php变量,但这是不可能的 在我的第三方物流中,我有:在Smarty模板3上显示php变量,php,templates,smarty,smarty3,Php,Templates,Smarty,Smarty3,我一直试图在smarty模板上显示php变量,但这是不可能的 在我的第三方物流中,我有: <a href="#">Welcome <strong><!--{$username}--></strong></a> 在我的php上我有: <?php require('../common/Smarty/config.php'); //Smarty Config Class require_once('../c
<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}" );
?>
我想做的就是在登录页面上显示用户的用户名
有什么帮助吗
提前感谢。在Smarty lib tpl中,您只需在希望用户名出现在login.tpl文件中的位置写入{$username} 改变这个
<a href="#">Welcome <strong><!--{$username}-->``</strong></a>
对此
<a href="#">Welcome <strong>{$username}</strong></a>
以上内容适用于我顺便说一句,我将其用作Smarty DelimitersAt
$Smarty->display(“{$template}”)代码>,smarty需要模板文件名或其他有效的模板资源。我认为将html注释滥用为聪明的删除者并不是最佳选择。假设您希望在代码中实际使用html注释,则可能会出现smarty语法错误,然后模板会正确显示,图像和css都很好,问题是试图显示$user\u name变量。事实上,如果我删除:$user\u name,并添加类似于“Peter”的内容,模板就会显示该名称。您是否发现任何错误?你得到的是什么而不是转换后的值?我什么都没有,但如果我加上:$smarty->assign(“用户名”,Peter);对于Instance,我得到了:欢迎Peter!。看起来好像没有从数据库中获取用户名(但它正在登录)。$user_name变量在Login.php类上不起作用,我得到:Welcome{$username}。(我不使用{}作为delimters,我使用以下调试:在php文件到达smarty var声明之前,在php文件中回显$user_name。您得到了什么?您好,很抱歉我因为个人紧急情况不得不出差。无论如何,上面的代码正在工作。谢谢您的帮助。我非常感谢。