1. 下載最新的smarty。php
2. 下載的smarty內核文件夾libs,放入php網站文件夾內。(安全起見,可自行修改文件夾名,如更名爲smarty)html
3. 分別在網站目錄下創建templates、templates_c、configs、cache四個文件夾。安全
4. 在templates/目錄下寫模板,創建index.htm內容爲:測試
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Insert title here</title>
- </head>
- <body>
- {$vice}
- </body>
- </html>
OK,咱們來測試一下,php調用smarty,編寫以下程序:網站
- <?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(vice,'hello vice!');
- $smarty->display('index.htm');
- ?>
ui
輸出結果:hello vice!spa