简体   繁体   中英

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.

On my tpl i have:

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

On my php i have:

<?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.

change this

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

to this

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

The above works for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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