Version 2.0 introduced the plugin architecture that is used for almost all the customizable functionality of Smarty. This includes:
在 Version 2.0 中增加了外掛結構(plugin architecture),而這些可以使用在幾 乎所有的客制化函式。這些結構包括:
With the exception of resources, backwards compatibility with the old way of registering handler functions via register_* API is preserved. If you did not use the API but instead modified the class variables $custom_funcs, $custom_mods, and other ones directly, then you will need to adjust your scripts to either use the API or convert your custom functionality into plugins.
為了避免資源的例外情況,Smarty 為了向前相容,所以仍然保留舊的使用 register_* API 的註冊處理函式(registering handler functions)。如果你沒有使用 API 而直接修改類別變 數 $custom_funcs,$custom_mods,或別的變數的話,則你需要修改你的腳本語言,讓你的腳本語言使用 API,或是將你所撰寫 的函式功能變成外掛。
Plugins are always loaded on demand. Only the specific modifiers, functions, resources, etc invoked in the templates scripts will be loaded. Moreover, each plugin is loaded only once, even if you have several different instances of Smarty running within the same request.
外掛會在需要的時候載入。只有某些修飾字,函式,資源等等的會在樣板程式中引用 到時才會載入。此外,就算在同個要求下有多個不同的 Smarty 實例,每個外掛還是只會載入一 次。
Pre/postfilters and output filters are a bit of a special case. Since they are not mentioned in the templates, they must be registered or loaded explicitly via API functions before the template is processed. The order in which multiple filters of the same type are executed depends on the order in which they are registered or loaded.
前/後過濾符號與輸出過濾符號則都是特殊例子。雖然在樣板中不會被提到,但是她 們必須在樣板被處理前,使用 API 函式載入或註冊。同形過濾符號的執行順序決定於註冊或載 入的順序。
The plugins directory can be a string containing a path or an array containing multiple paths. To install a plugin, simply place it in one of the directories and Smarty will use it automatically.
變數 plugins directory 的值可以是路徑的字串,或是多個路徑所組成的陣列。如果要安裝外掛,只要將其放在 plugins directory 內的路徑中,Smarty 就會自動取得。