smarty配置和用法

1.解压:Smarty-2.6.20.tar.gz
2.把Smarty-2.6.20/libs下的全部Copy到php目录下的一个包中(我取名smarty/classes)
3.在smarty下建立test.php,
4.//-------------------------------------------------------------------------
 <?php
   
       include("./aa/Smarty.class.php"); //包含smarty类文件

      $smarty = new smarty();  //建立smarty实例对象$smarty
      $smarty -> template_dir = "./templates";  //模板存放目录
   $smarty -> compile_dir = "./cc";  //编译目录
   $smarty->config_dir = "./config";
   $smarty->cache_dir = "./cache";
     
      //----------------------------------------------------
      //左右边界符,默认为{},但实际应用当中容易与JavaScript
      //相冲突,所以建议设成<{}>;或其它。
      //----------------------------------------------------
      $smarty -> left_delimiter = "{{";  //左定界符
   $smarty -> right_delimiter = "}}";  //右定界符

      $smarty -> assign('name', '小林'); //进行模板变量替换
 
   $smarty -> assign('nn', '奥运会'); //进行模板变量替换
      //编译并显示位于./templates下的index.tpl模板
      $smarty->display('test.txt');
   ?>;
//------------------------------------------------------------
5.在smarty/templates下建立模板文件test.tpl
 <html>
<head>

</head>
<body>
<hr/>
<table align="center">
<h1>

{{$name}}
</h1>


</table>


</body>
</html>
6.建立smarty/cc作为编译文件路径
7.访问http://localhost/dianzi/smarty/test.php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值