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?
You can do this by writing a custom plugin for fetching the content and assigning it to a template variable.
Example 18-7. componentized template function.load_ticker.php - drop file in $plugins directory
index.tpl
|
See also {include_php}, {include} and {php}.