Traditionally, programming templates into your applications goes as follows: First, you accumulate your variables within your PHP application, (maybe with database queries.) Then, you instantiate your Smarty object, assign the variables and display the template. So lets say for example we have a stock ticker on our template. We would collect the stock data in our application, then assign these variables in the template and display it. Now wouldn't it be nice if you could add this stock ticker to any application by merely including the template, and not worry about fetching the data up front?
傳統情況下,在應用程式中使用樣板的步驟如下:首先你要先在你的 PHP 應用程式 中累積變數(也可能是資料庫查詢式)。再來是使用(instantiate)Smarty 物件,指定變數值 與呈現樣板。舉例來說,假設現在在樣板中有一個股票行情計時器,然後應用程式會收集股票的 資料,然後將收集到的資料指定到樣板內然後顯示出來。現在請考慮一下如果只是將樣板包含進 來的話這樣就可以使用這個股票行情計時器了嗎?是否可以順利的取得資料呢?
You can do this by writing a custom plugin for fetching the content and assigning it to a template variable.
你可以撰寫一個客制的外掛程式取得股票資料並指定給樣板的變數,如此就可以完成 上述的工作。