smarty教程-smarty入门基础应用实例教程

smarty教程-smarty入门基础应用实例教程
/*
smarty选用的一种缓存技术,它可以将用户最终看到的HTML文件缓存成一个静态的HTML页,当设定smarty的cache属性为true时,在smarty设定的cachetime期内将用户的WEB请求直接转换到这个静态的HTML文件中来,这相当于调用一个静态的HTML文件。

采用smarty编写的程序可以获得最大速度的提高,这一点是相对于其它的模板引擎技术而言的。

*/

$servername  = 'localhost';
$dbname='whois';//数据库教程名称,需修改为您当前使用的库名称
$tbname='post';//数据表名称,不用修改
$name='root';//数据库用户名,需修改
$password='xxxxxxx';//数据库链接密码,需修改
require_once '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->caching = false;
$db=mysql教程_connect($servername,$name,$password)or die ('服务器连接错误。');
$ii=mysql_select_db("$dbname")or die("不能选择数据库");
mysql_query("set names 'gbk'");

$title ='smarty 教程';
$keyword ='smarty模板,smarty教程';
$description ='提供简单的smarty入门教程';
$smarty->assign('title',$title);
$smarty->assign('keyword',$keyword);
$smarty->assign('description',$description);

$smarty->display('index.html'); //使用 smartytemplatestemplatesindex.html 模板


?>

index.html模板文件

<title><!--{$title}--></title>
<meta name="keywords" content="<!--{$keyword}-->" />
<meta name="description" content="<!--{$description}-->" />

{include file='head.tpl'}
{include_php file='body.php'}
{include file='footer.tpl'}

<?
/*
smarty 模板变量

.{$name}: 模板变量,smarty中的核心组成,采用smarty定义的左边界符{与右边界符}包含着、以PHP变量形式给出,在smarty程序中将使用
$smarty->assign("name", "李晓军");将模板中的$name替换成“李晓军”三个字。

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值