程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP基礎知識 >> smarty模板基礎配置詳解

smarty模板基礎配置詳解

編輯:PHP基礎知識
 

在Smarty目錄中建立templates,templates_c,configs,cache目錄。以便Smarty進行編譯和緩存。

建立smarty_inc.php文件對smarty進行配置如下:
 

<?php
include_once("./smarty/Smarty.class.php"); //包含smarty類文件
$smarty = new Smarty(); //建立smarty實例對象$smarty
$smarty->caching=false; //開發是不建議開啟緩存
$smarty->template_dir="./templates"; //設置模板目錄
$smarty->compile_dir="./templates_c"; //設置編譯目錄
$smarty->cache_dir="./cache"; //緩存文件夾
$smarty->cache_lifetime=60;
$smarty->left_delimiter = "<{"; //左定界符
$smarty->right_delimiter = "}>"; //右定界符
?>
 

行測試,在根目錄下建立index.php文件:

<?php
include("smarty_inc.php");
$val= array("丁慶","董丹鳳","情侶");
$smarty->assign("name",$val);
$smarty->display("index.html");
?>
在templates下建立index.html模板:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<title>測試頁面</title>
</head>
<body>
<{foreach from=$name item=x}>
數組內容:<{$x}> <br/>
<{/foreach}>
</body>
</html>
好了,大功告成,就是這麼簡單,開始你的smarty之旅吧。。。

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved