佈景主題是如何運作的?

From Joomla! Documentation

This page is a translated version of the page How are templates executed? and the translation is 100% complete.
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎português • ‎português do Brasil • ‎русский • ‎українська • ‎中文(台灣)‎

佈景主題的執行是一個2階段運作,完整利用了PHP解析器的佈景主題設計工具提供了相當高的靈活彈性與性能。佈景主題會根據文件物件來執行,所以$this 總會是物件 JDocument class 實例化。

在佈景主題開始執行之前,會先執行元件,然後儲存於緩衝供未來使用。

接著佈景主題依以下程序執行:

  • 載入佈景主題參數(假使有的話)
  • 載入佈景主題語言(假使有的話)
  • 假使啟用相容模式,則會將設定變數複製為全站
  • 載入佈景主題檔案 (index.php) 並透過PHP執行,儲存輸出於緩衝,此為二階段程序中的第一階段。所有在標籤 <?php and ?> 都會當成 PHP 程式語言來執行。所有在標籤以外的會被輸出,其餘的會被忽略。由於輸出是被緩衝起來,所以在此階段,客戶端的瀏覽器看不到任何東西。
  • 尋找 favicon.ico 檔案。首先會在 Joomla! 根目錄尋找,接著在佈景主題根目錄,找到的話,後者會覆蓋前者。
  • 此時,緩衝於第一階段的輸出會為 <jdoc:include> 元素進行解析。這是第二階段。根據找到的每一個jdoc元素,會載入適當的解析器 class ,並且會呼叫其解析 method。從解析方法輸出的內容,會取代輸出緩衝中的 <jdoc:include> 元素。In the case of module renderer classes this triggers the execution of the modules and the buffering of their output.
  • 加入佈景主題特定的 HTTP 頁首到要輸出的頁首清單中
  • Control is then passed back to the JApplication object which will handle the rest of the process of getting the now rendered web page back to the client web browser.