小说网 找小说 无限小说 烟雨红尘 幻想小说 酷文学 深夜书屋

smarty精品教程一(高级篇)

学习php模板开发有一两天了,对比了一下。还是smarty模板功能强大一些。

所以建议大家就学samrty模板吧!(个人观点)

1.我们要配置好php环境

2.下好samrty模板文件 下载地址->http://www.smarty.net/download.php

3.smarty中文手册 下载地址->http://www.smarty.net/manual/en/(官方英文)

http://www.hbcms.org.cn/main/smarty/index.html(中文)

现在我们就可以学习smarty了.

eg1:

1.php

<?php
/*********************************************
QQ:283093141

*********************************************/
include_once('../libs/Smarty.class.php');   //包含smarty类文件

$smarty= new Smarty;  //实例化Smarty类

$smarty->template_dir= './templates';  //设置模板目录
$smarty->compile_dir= './templates_c';      //设置编译目录
$smarty->cache_dir= './cache';              //设定缓存目录
$smarty->caching = ture;
//----------------------------------------------------
//左右边界符,默认为{},但实际应用当中容易与JavaScript
//相冲突,所以建议设成<{}>或其它。
//----------------------------------------------------
//$smarty->left_delimiter = "<{";
//$smarty->right_delimiter = "}>";

$smarty->assign("name", "fkedwgwy"); //进行模板变量替换

//编译并显示位于./templates下的index.tpl模板
$smarty->display("1/i1.tpl");
?>

 

i1.tpl

{* 显示是smarty变量识符里的用*包含的文字为注释内容*}
{include file="1/h1.tpl"}{*页面头*}
<center>大家好,我叫{$name}, 欢迎大家阅读我的smarty学习材料。</center>
{include file="1/f1.tpl"}{*页面尾*}

h1.tpl

<html>
<head>
<title>fkedwgwy---smarty教程</title>
</head>
<body>

 

f1.tpl

<hr>
<center> fkedwgwy作品------smarty教程 </center>
<hr>
</body>
</html>

 

ouiprint:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0037)http://127.0.0.1/smartyer/a/php/1.php -->
<HTML><HEAD><TITLE>fkedwgwy---smarty教程</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.3790.4237" name=GENERATOR></HEAD>
<BODY>
<CENTER>大家好,我叫fkedwgwy, 欢迎大家阅读我的smarty学习材料。</CENTER>
<HR>

<CENTER>fkedwgwy作品------smarty教程 </CENTER>
<HR>
</BODY></HTML>

这就是第一个smarty实例`````

很简单吧```

posted on 2008-05-13 16:13  王峰炬  阅读(85)  评论(0编辑  收藏  举报

导航