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:
Quote:
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.
THE FIX:
To cache these templates, we add the following:
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:
i have a php script that i am having trouble with. it is not written for vbulletin, but i would like to include it in my vb's template. this script has about 3-4 php files. i create a php file from which i run my script (followed the instructions from How to create a vbulletin powered page). i only include once the index.php of my script, which runs other php files from inside of it.
my problem is the following: when i run the script, everything is fine, the template is there etc. when i enter the details the script asks for, and i hit submit, the new window that opens does not have the vb template. i've tried everything, no luck. the window that opens when i hit submit has no action (etc. xxx.php?=something.) its just xxx.php. the funny thing is that if i have an error in my form, the template stays as it is even though a new window opens. the problem only occurs when i hit submit. please help
Caching templates means that all the templates are fetched with a single query at the beginning of the script, if you fetch un-cached templates during the script the script has to make database queries to fetch it. Thus using server resources that you don't need to.