Smarty快速入門

 1. 下載最新的smarty。php

       2. 下載的smarty內核文件夾libs,放入php網站文件夾內。(安全起見,可自行修改文件夾名,如更名爲smarty)html

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

ui

 

 

輸出結果:hello vice!spa

相關文章
相關標籤/搜索