這篇文章將為大家詳細講解有關Smarty如何配置使用,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

具體如下:
下載Smarty(這里以Smarty-2.6.26為例)。解壓下載的文件(目錄結構還蠻復雜的)。接下來演示給大家一個安裝實例,看過應該會舉一反三的。
(1) 在根目錄下建立了新的目錄learn/,再在learn/里建立一個目錄smarty/。將剛才解壓縮出來的目錄的libs/拷貝到smarty/里,再在smarty/里新建templates目錄,templates里新建cache/,templates/,templates_c/, config/。
(2) 新建一個模板文件:index.tpl,將此文件放在learn/smarty/templates/templates目錄下,代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=gb2312">
<title>Smarty</title></head>
<body>{#$hello#}</body>
</html>新建index.php,將此文件放在learn/下:
<?php
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;//設置各個目錄的路徑,這里是安裝的重點
$smarty->template_dir ="smarty/templates/templates";
$smarty->compile_dir ="smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir ="smarty/templates/cache";
//smarty模板有高速緩存的功能,如果這里是true的話即打開caching,但是會造成網(wǎng)頁不立即更新的問題,當然也可以通過其他的辦法解決
$smarty->caching = false;
$smarty->left_delimiter = "{#"; //重新定義邊界,因為默認邊界“{}“符,在html頁面中嵌入js腳本文件編寫代碼段時使用的就是”{}“符,自定義邊界符還可以是<{ }>, {/ /} 等
$smarty->right_delimiter = "#}";
$hello = "Hello World!";//賦值
$smarty->assign("hello",$hello);//引用模板文件
$smarty->display('index.tpl');?>(3) 執(zhí)行index.php就能看到Hello World!了。
關于“Smarty如何配置使用”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
文章標題:Smarty如何配置使用-創(chuàng)新互聯(lián)
標題鏈接:http://chinadenli.net/article12/dgpgdc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、手機網(wǎng)站建設、網(wǎng)站排名、網(wǎng)站收錄、品牌網(wǎng)站設計、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容