Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Articles Thread, How-To Cache Templates in vBulletin; How-To Cache Templates This article assumes that you are building your own product with end-user options. INTRODUCTORY ON CACHING TEMPLATES: ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=4110


Reply
LinkBack Thread Tools Display Modes
How-To Cache Templates
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
05-10-2008, 06:57 PM
 
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:
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: PHP Code:
PHP Code:
$actiontemplates['insertsettings'] =& $actiontemplates['options'];


below the $actiontemplates array.


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:
PHP Code:
$actiontemplates = array(
    
'options' => array(
        
'gtblog_options',
        
'gtblog_radio_option',
        
'newpost_errormessage',
    )

Back to the interface...
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... Egypt.Com EnForum

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:
PHP Code:
<input name="do" value="insertsettings" type="hidden">
With this new information we fix the uncached issue by adding PHP Code:
PHP Code:
$actiontemplates['insertsettings'] =& $actiontemplates['options'];


below the $actiontemplates array.

The final code should look like this: <div class="smallfont" style="margin-bottom: 2px;">PHP Code:
PHP Code:
           $actiontemplates = array(
    
'options' => array(
        
'gtblog_options',
        
'gtblog_radio_option',
        
'newpost_errormessage',
    )
$actiontemplates['insertsettings'] =& $actiontemplates['options'];
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!
 
 
 
Reply

Articles Thread, How-To Cache Templates in vBulletin; How-To Cache Templates This article assumes that you are building your own product with end-user options. INTRODUCTORY ON CACHING TEMPLATES: ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=4110


Bookmarks

Tags
cache, howto, templates


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Templates 1.0 Developer Software and Programs 0 13-11-2008 12:45 AM
Egypt police find huge weapons cache in Sinai Developer News 0 01-09-2008 08:51 PM
Cache accelerate component for Joomla, Mambo Developer Templates for Joomla 1.5 0 18-08-2008 08:42 PM
Egypt finds weapons cache near Gaza border SABRAWY News 0 01-06-2008 03:36 PM
Egyptian police uncover explosives cache near Gaza border SABRAWY News 0 18-02-2008 10:46 PM