Smarty生成静态页面的方法

8 篇文章 0 订阅
 
  1. <?php  
  2. /*  
  3.  *Smarty生成静态页面  
  4.  *Smarty生成静态页面的条件  
  5.  *调用Smarty类及配置相关属性  
  6.  *使用fetch()方法实现生成静态页面  
  7.  */   
  8.   
  9. //调用Smarty类   
  10. include ( "smarty/smarty.class.php" );  
  11.   
  12. //实例化Smarty和配置Smarty属性   
  13. $smarty  =  new  Smarty();     //实例化Smarty对象   
  14. $smarty ->template_dir =  "smarty/templates" ;     //模板文件的目录   
  15. $smarty ->compile_dir =  "smarty/template_c" ;     //编译的模板文件   
  16. $smarty ->config_dir =  "smarty/configs" ;         //配置文件目录   
  17. $smarty ->cache_dir =  "smarty/cache" ;            //缓存的所有文件   
  18. $smarty ->caching = false;  
  19. $smarty ->left_delimiter =  "<{" ;  
  20. $smarty ->right_delimiter =  "}>" ;  
  21.   
  22. //Smarty生成静态页面的代码   
  23. $smarty ->assign( "contect""HelloWorld!" );  
  24. $contect  =  $smarty ->fetch( "index.tpl" );  
  25. $fp  =  fopen ( "index.html""w" );  
  26. fwrite($fp$contect );  
  27. fclose($fp )  
  28. ?>  
  29.   
  30. //index.tpl模版   
  31. <html>  
  32. <head>  
  33. <title>Test</title>  
  34. </head>  
  35. <body>  
  36. <{$contect }>  
  37. </body>  
  38. </html>  
  39.   
  40. //生成后的index.html   
  41. <html>  
  42. <head>  
  43. <title>Test</title>  
  44. </head>  
  45. <body>  
  46. HelloWorld!  
  47. </body>  
  48. </html> 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值