SMARTY學(xué)習(xí)手記
更新時間:2007年01月04日 00:00:00 作者:
學(xué)習(xí)PHP不能不提下SMARTY,作為著名的模板程序,SMARTY自然有其優(yōu)勢。下面是我總結(jié)的自己的一點學(xué)習(xí)心得吧!
=====================================
先在smarty.php.net下載最新smarty
將libs文件夾放在你的WEB目錄下,我是放在smarty下的,目錄情況如下:e:/smarty/libs
在smarty目錄下新建如下文件夾:
templates(這里放你的模板文件,即tpl文件)
configs
templates_c(自動將編譯完的文件轉(zhuǎn)成PHP放在這)
cache
然后在wwwroot目錄下建立index.php:
<?php
include "smarty/libs/Smarty.class.php";
define('__SITE_ROOT', 'e:/smarty'); // 最後沒有斜線
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
//$tpl->left_delimiter = '<{'; 可根據(jù)需要更改。
//$tpl->right_delimiter = '}>';
$tpl->assign('name','world!');
$tpl->display('index.tpl')
?>
在template目錄下建立index.tpl:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
hello,{$name}~.
</body>
</html>
然后本地index.php顯示出hello,world!~.
=====================================
先在smarty.php.net下載最新smarty
將libs文件夾放在你的WEB目錄下,我是放在smarty下的,目錄情況如下:e:/smarty/libs
在smarty目錄下新建如下文件夾:
templates(這里放你的模板文件,即tpl文件)
configs
templates_c(自動將編譯完的文件轉(zhuǎn)成PHP放在這)
cache
然后在wwwroot目錄下建立index.php:
<?php
include "smarty/libs/Smarty.class.php";
define('__SITE_ROOT', 'e:/smarty'); // 最後沒有斜線
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
//$tpl->left_delimiter = '<{'; 可根據(jù)需要更改。
//$tpl->right_delimiter = '}>';
$tpl->assign('name','world!');
$tpl->display('index.tpl')
?>
在template目錄下建立index.tpl:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
hello,{$name}~.
</body>
</html>
然后本地index.php顯示出hello,world!~.
相關(guān)文章
PHP簡單系統(tǒng)數(shù)據(jù)添加以及數(shù)據(jù)刪除模塊源文件下載
今天我們總結(jié)一下PHP簡單信息系統(tǒng)MySQL中數(shù)據(jù)添加模塊以及刪除模塊的學(xué)習(xí)內(nèi)容。2008-06-06php使用Smarty的相關(guān)注意事項及訪問變量的幾種方式
使用Smarty的相關(guān)注意事項及訪問變量的幾種方式分享,需要的朋友可以參考下。2011-12-12