Smarty快速入门

 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. ?>  

<?php include('smarty/Smarty.class.php'); //程序目录 const DIR_SEP = DIRECTORY_SEPARATOR; define('SITE_ROOT', dirname(__FILE__).DIR_SEP); $smarty = new Smarty; $smarty->template_dir = SITE_ROOT.'templates'.DIR_SEP; $smarty->complie_dir = SITE_ROOT.'templates_c'.DIR_SEP; $smarty->config_dir = SITE_ROOT.'configs'.DIR_SEP; $smarty->cache_dir = SITE_ROOT.'cache'.DIR_SEP; $smarty->assign('world','hello world!'); $smarty->display('index.htm'); ?>

 

 

输出结果:hello vice!

转载于:https://www.cnblogs.com/one66/p/3600602.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值