簡體   English   中英

在Smarty模板3上顯示php變量

[英]Display php Variable on Smarty Template 3

我一直試圖在一個聰明的模板上顯示一個php變量,但這是不可能的。

在我的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}" );
?>

我試圖做的是在登錄頁面上也顯示用戶的用戶名。

有什么幫助嗎?

提前致謝。

在您的Smarty lib tpl中,您只需要在希望用戶名出現在login.tpl文件中的地方寫上{$ username}。

改變這個

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

對此

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

以上對我有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM