- 您的當前位置: 網(wǎng)站首頁 ? 信息講堂 ? 技術文章 ? php超強模板引擎smarty簡單配置
- ***
php超強模板引擎smarty簡單配置
1.從從smarty官網(wǎng)下載smarty,然后解壓到根目錄。
2.將全部解壓的文件其中一個libs目錄拷貝到根目錄下面。里面是smarty用到的類。
3.新建三個文件夾
cache —— 緩存文件夾
templates —— 模板文件夾
templates_c —— 模板編譯文件夾
4.在網(wǎng)站根目錄下面創(chuàng)建配置文件,建立smary_config.php,在其中輸入如下代碼:
include_once ("libs/Smarty.class.php"); //包含smarty文件
$smarty = new Smarty(); //建立實例對象
$smarty->config_dir="libs/Config_File.class.php"; //目錄變量
$smarty->caching = false; //是否使用緩存
$smarty->template_dir="./templates"; //設置模板目錄
$smarty->compile_dir="./templates_c"; //設置模板編譯目錄
$smarty->cache_dir="./smarty_cache";//緩存文件夾
$smarty->left_delimiter="<{"; $smarty->right_delimiter="}>";
5.templates 目錄下建立index.html文件,內(nèi)容如下:
<html >
<head>
<title>({$title}) </title>
<meta http-equiv=”Content-type” content=”text/html; charset=utf-8″>
<META NAME=”Author” CONTENT=”">
<META NAME=”Keywords” CONTENT=”">
<META NAME=”Description” CONTENT=”">
</head>
<body>
({$title})<p />
({$content})
</body>
</html>
6.在根目錄下建立index.php文件,內(nèi)容如下:
<?php
assign("title", "測試成功了,這是標題");
$smarty ->assign("content", "這是內(nèi)容");
$smarty->display(index.html);
?>
7.如果沒有什么意外發(fā)生,瀏覽器中打開index.php 基本配置已經(jīng)成功。
2.將全部解壓的文件其中一個libs目錄拷貝到根目錄下面。里面是smarty用到的類。
3.新建三個文件夾
cache —— 緩存文件夾
templates —— 模板文件夾
templates_c —— 模板編譯文件夾
4.在網(wǎng)站根目錄下面創(chuàng)建配置文件,建立smary_config.php,在其中輸入如下代碼:
include_once ("libs/Smarty.class.php"); //包含smarty文件
$smarty = new Smarty(); //建立實例對象
$smarty->config_dir="libs/Config_File.class.php"; //目錄變量
$smarty->caching = false; //是否使用緩存
$smarty->template_dir="./templates"; //設置模板目錄
$smarty->compile_dir="./templates_c"; //設置模板編譯目錄
$smarty->cache_dir="./smarty_cache";//緩存文件夾
$smarty->left_delimiter="<{"; $smarty->right_delimiter="}>";
5.templates 目錄下建立index.html文件,內(nèi)容如下:
<html >
<head>
<title>({$title}) </title>
<meta http-equiv=”Content-type” content=”text/html; charset=utf-8″>
<META NAME=”Author” CONTENT=”">
<META NAME=”Keywords” CONTENT=”">
<META NAME=”Description” CONTENT=”">
</head>
<body>
({$title})<p />
({$content})
</body>
</html>
6.在根目錄下建立index.php文件,內(nèi)容如下:
<?php
assign("title", "測試成功了,這是標題");
$smarty ->assign("content", "這是內(nèi)容");
$smarty->display(index.html);
?>
7.如果沒有什么意外發(fā)生,瀏覽器中打開index.php 基本配置已經(jīng)成功。