How-To Cache Templates

Joe Velez began developing for the web in 1998. He is an avid vBulletin user and volunteers his services as a vbulletin.org administrator. He currently spends his time maintaining and developing allnurses.com.

This article assumes that you are building your own product with end-user options.

INTRODUCTORY ON CACHING TEMPLATES:
Whenever you create a product you should cache your templates by adding them to the $globaltemplates and $actiontemplates array.

$globaltemplates are templates loaded by all actions.$actiontemplates are templates loaded when a specified action is called such as $do (e.g. ?do=edit).

TEMPLATES NOT CACHED:

When displaying an "error message" on the same page I notice that the templates are not cached.

This is due to the fact that the "action" does not have any templates to load (via $actiontemplates).*

To remedy this some coders add the uncached templates to the $globaltemplates array. However, this is the wrong way to do it. As a coder, our obligation is to cache the least amount of templates to consume less memory.

*NOTE: This usually happens when you are redirected back to the page via $_POST.

EXAMPLE:
A blog product that I am working on will display an error message to the end-user upon an error. The error message will be on the same page (redirected back via $_POST) not a STANDARD_ERROR page.

The interface is full of options that at the very least requires the end-user to enter a TITLE and DESCRIPTION.

The interface is accessible by the action "do=options".
To cache the required templates to build the interface I add the templates to the $actiontemplates array such as: