The Arcive of vBulletin Modifications Site. |
|
|
How-To Cache Templates
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:
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: PHP Code:
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: PHP Code:
whenever the end-user forgets to enter a TITLE an error message is displayed. (The system requires the title.) When the error message is displayed none of the templates are cached. We are missing something... ![]() To remedy this we need to look at the $_POST "do" action of the form. A closer look at the html source tells me that the "do" action is HTML Code:
<input name="do" value="insertsettings" type="hidden">
PHP Code:
The final code should look like this: PHP Code:
|
|
#2
|
|||
|
|||
|
Good info, most people dont' follow these rules.
|
|
#3
|
||||
|
||||
|
gracias se?or...
feedback is always good and I do appreciate it |
|
#4
|
||||
|
||||
|
Thanks for the tutorial!
|
|
#5
|
||||
|
||||
|
When creating a modification using a product, you can also use this method in a plugin.
Choose 'Cache_templates' and put the PHP code as: PHP Code:
PHP Code:
![]() Nice tutorial ![]() Good job ^_^ |
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
||||
|
||||
|
HTML Code:
$actiontemplates = array(
'edit' => array(
'template_name',
),
'file' => array(
'template_name',
),
'event' => array(
'template_name',
)
);
|
|
#8
|
||||
|
||||
|
Quote:
|
|
#9
|
||||
|
||||
|
it should be ?do=edit, ?do=file, ?do=event
if you use anything else cache the template(s) using $globaltemplates |
|
#10
|
|||
|
|||
|
Question, since this issue just popped up on my forum with Calorie's photoplog thumb hack. (here).
The only template call that I see in the .php file is this: Code:
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_photoplog_thumbs') . '";');
|
![]() |
|
|