简体   繁体   English

在Smarty模板3上显示php变量

[英]Display php Variable on Smarty Template 3

I've been trying to display a php variable on a smarty template, but it have been impossible. 我一直试图在一个聪明的模板上显示一个php变量,但这是不可能的。

On my tpl i have: 在我的tpl上,我有:

<a href="#">Welcome <strong><!--{$username}--></strong></a>

On my php i have: 在我的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}" );
?>

What im trying to do is too display the username of the user at login page. 我试图做的是在登录页面上也显示用户的用户名。

Any help? 有什么帮助吗?

Thanks in advance. 提前致谢。

In your Smarty lib tpl you should just write {$username} where you want the user name to appear in the login.tpl file. 在您的Smarty lib tpl中,您只需要在希望用户名出现在login.tpl文件中的地方写上{$ username}。

change this 改变这个

<a href="#">Welcome <strong><!--{$username}-->``</strong></a>

to this 对此

<a href="#">Welcome <strong>{$username}</strong></a>

The above works for me 以上对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM