2013-08-24 62 views
-2

我編碼爲橫幅旋轉。我想知道如何將它添加到tpl文件以顯示它?顯示tpl的最佳方法?

<?php 

    $fcontents = join ('', file ('banner_ads.txt')); 
    $s_con = split("~",$fcontents); 

    $banner_no = rand(0,(count($s_con)-1)); 
    echo $s_con[$banner_no]; 

?> 
+4

請告訴我們您由TPL的意思。你使用Smarty嗎? –

+1

是的,我想將此添加到我的tpl文件 – user2674785

回答

1

首先,您的頁面應該包含Smarty模板引擎。在PHP文件中,你應該放置你的邏輯。在這個文件中,你獲取橫幅。然後,您可以將其分配給您的模板。

您的代碼將是這樣的:現在

include('Smarty.class.php'); 
$smarty = new Smarty; 

$fcontents = join ('', file ('banner_ads.txt')); 
$s_con = split("~",$fcontents); 
$banner_no = rand(0,(count($s_con)-1)); 
$smarty->assign('banner', $s_con[$banner_no]); 

$smarty->display('index.tpl'); 

,在你的模板,只需將橫幅是這樣的:

{$banner} 
+0

感謝您的幫助 – user2674785