Smarty的基本配置

一、下载smarty压缩包  
二、解压smarty压缩包,把里面的libs文件夹复制到网站的根目录下面,然后建立两个文件夹分别是templates 和  templates_c, templates 文件夹是存放模版文件的, templates_c 文件夹是存放编译文件的
三、输出简单的hello,world
建立模版文件hello.tpl放到templates文件夹下面  代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<{$hello}>
</body>
</html>
建立一个php文件放到根目录下  代码如下:
<?php
   include_once("libs/Smarty.class.php");   // 包含smarty类文件
   $smarty=new Smarty();   // 建立smarty实例对象$smarty
   $smarty->caching=false;  // 是否使用缓存
   $smarty->template_dir="./templates/";  // 设置模版目录
   $smarty->compile_dir="./templates_c/";  //设置编译目录
   $smarty->cache_dir="./smarty_cache/";  // 缓存文件夹
   //  设置作用边界符  默认是{  }  一般用<{ }>
   $smarty->left_delimiter="<{";
   $smarty->right_delimiter="}>";
   // 从php分配变量给模版文件
   $smarty->assign("hello","hello,world");
   $smarty->display("hello.tpl");
     
?>
这样就可以输出hello,world了   这也是smarty的简单配置,关于smarty的更多内容敬请关注。。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值