php簡單smarty入門程式執行個體
首先要有3個檔案夾configs、templates、templates_c,在configs檔案夾中有一個設定檔:test.conf,代碼:
| 1 2 3 4 |
title = Welcome to Smarty! cutoff_size = 40 [setup] bold = true |
templates中有模板檔案:test.htm:
| 1 2 3 4 5 6 7 8 |
Smarty Test Hello, {$Name} |
php檔案代碼:
| 1 2 3 4 5 6 |
require 'libs/Smarty.class.php'; //包含Smarty類庫檔案 $smarty = new Smarty; //建立一個新的Smarty對象 $smarty->assign("Name","Simon"); //對模版中的變數賦值 $smarty->display('test.htm'); //顯示頁面 ?> |
運行後顯示的頁面代碼:
| 1 2 3 4 5 6 7 8 |
Smarty Test Hello, Simon |
運行之後,還在templates_c檔案夾中產生一個php檔案:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* Smarty version 2.6.22, created on 2009-03-19 13:20:00 compiled from test.htm */ ?> Smarty Test Hello, _tpl_vars['Name']; ?> |
這個檔案就是瀏覽所顯示出來的效果。
http://www.bkjia.com/PHPjc/1015338.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1015338.htmlTechArticlephp簡單smarty入門程式執行個體 首先要有3個檔案夾configs、templates、templates_c,在configs檔案夾中有一個設定檔:test.conf,代碼: 1 2 3 4 title = W...