首页 > 其他 > 详细

Smarty快速入门

时间:2014-03-16 07:25:54      阅读:474      评论:0      收藏:0      [点我收藏+]

 1. 下载最新的smarty。

       2. 下载的smarty内核文件夹libs,放入php网站文件夹内。(安全起见,可自行修改文件夹名,如改名为smarty)

       3. 分别在网站目录下建立templates、templates_c、configs、cache四个文件夹。

       4. 在templates/目录下写模板,建立index.htm内容为:

 

  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  4. <title>Insert title here</title>  
  5. </head>  
  6. <body>  
  7.     {$vice}  
  8. </body>  
  9. </html>  

OK,我们来测试一下,php调用smarty,编写如下程序:

 

  1. <?php  
  2. include(‘smarty/Smarty.class.php‘);  
  3. //程序目录  
  4. const DIR_SEP = DIRECTORY_SEPARATOR;  
  5. define(‘SITE_ROOT‘, dirname(__FILE__).DIR_SEP);  
  6.   
  7. $smarty = new Smarty;  
  8. $smarty->template_dir = SITE_ROOT.‘templates‘.DIR_SEP;  
  9. $smarty->complie_dir  = SITE_ROOT.‘templates_c‘.DIR_SEP;  
  10. $smarty->config_dir   = SITE_ROOT.‘configs‘.DIR_SEP;  
  11. $smarty->cache_dir    = SITE_ROOT.‘cache‘.DIR_SEP;  
  12.   
  13. $smarty->assign(vice,‘hello vice!‘);  
  14. $smarty->display(‘index.htm‘);  
  15. ?>  

 

 

输出结果:hello vice!

Smarty快速入门,布布扣,bubuko.com

Smarty快速入门

原文:http://www.cnblogs.com/one66/p/3600602.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!