1 / 9

PHPTAL 樣板引擎

PHPTAL 樣板引擎. PHPTAL 的特色 : 樣版完全由 xml/xhtml 標籤所構成 完成樣板時就可以透過瀏覽器查看版型 也就是 WYSIWYG 的樣板引擎 (What you see is what you get) 樣板引擎的比較表. PHPTAL 完成頁面流程. 使用者呼叫 php 頁面 (ex:http://localhost/123.php) 該 php page 會載入 phptal 物件庫 然後 new a template object ,以樣板檔案的 URI 為參數 php 檔案裡指定填在樣板裡的資料和物件

Download Presentation

PHPTAL 樣板引擎

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHPTAL 樣板引擎 PHPTAL的特色: • 樣版完全由xml/xhtml 標籤所構成 • 完成樣板時就可以透過瀏覽器查看版型 • 也就是WYSIWYG的樣板引擎 (What you see is what you get) 樣板引擎的比較表

  2. PHPTAL完成頁面流程 • 使用者呼叫php頁面(ex:http://localhost/123.php) • 該php page 會載入phptal物件庫 • 然後 new a template object,以樣板檔案的URI為參數 • php 檔案裡指定填在樣板裡的資料和物件 • 執行(parse template , substitute and display )

  3. PHPTAL語法 • PHPTAL 利用tag內的attribute來實做樣板語言 • Namespace有下列幾種 • TAL (最常用的ns) • METAL(網頁區塊的利用) • I18N (國際化語言的支援) • PHPTAL • *:block(同標籤裡的ns可以只先定義一次) • PHPTALES(在tal ns 的參數的ns, ex: string: … )

  4. 常用的attribute • tal:define 定義變數供樣板使用 Ex: <span tal:define = “global destname path/to/existing/variable” 有global和local的變數 • tal: condition 若條件判斷為true,顯示標籤的內容 <span tal:condition =“identidied”> Welcome member</span>

  5. 常用的attribute • tal:repeat 用來操作陣列 EX: <tr tal:repeat="item some/result"> <td tal:content="item">text replaced by item</td> </tr> • tal:content 將變數帶入標籤的內容中 Ex: <span tal:define="myvar string:my string"/> <span tal:content="myvar">will be replaced</span>

  6. 效能問題 • 若每次使用者點閱網頁時,樣板引擎都要先parse一次樣板,會使得顯示完整畫面的速度更加緩慢 • 需要有cache的機制,第一次parse一個頁面時,最好產生出一個完全編譯成動態網頁語言的檔案(例如:將樣板的語言置換php的程式碼) • 這樣才不會拖慢開網頁的速度

More Related