Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
How-To Cache Templates
Princeton
Join Date: Nov 2001
Posts: 6,903

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.

Vineland, NJ
by Princeton Princeton is offline 05 Jan 2006

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:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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...

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
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

With this new information we fix the uncached issue by adding
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

below the $actiontemplates array.

The final code should look like this:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Attached Images
File Type: gif 1.gif (18.7 KB, 711 views)
File Type: gif 1a.gif (26.3 KB, 1118 views)

Last edited by Princeton; 07 Jan 2006 at 15:21..
Views: 23519
Reply With Quote
Comments
  #2  
Old 23 Jan 2006, 22:52
PennylessZ28 PennylessZ28 is offline
 
Join Date: Mar 2002
Real name: Mike
Good info, most people dont' follow these rules.
Reply With Quote
  #3  
Old 23 Jan 2006, 23:30
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Real name: Joe Velez
gracias seņor...

feedback is always good and I do appreciate it
__________________
Latest Articles:
Liquid Layout = Less Ad Revenue?
How to Monetize Your Site
Improve Web Page Performance
How To Write For The Web


If it needs instructions, there's room for improvement.
Give users what they actually want, not what they say they want. And whatever you do, don't give them new features just because your competitors have them!
Reply With Quote
  #4  
Old 24 Jan 2006, 00:59
Snake's Avatar
Snake Snake is offline
 
Join Date: Mar 2005
Location: Cleveland, OH
Real name: Josh
Thanks for the tutorial!
Reply With Quote
  #5  
Old 24 Jan 2006, 19:40
Marky's Avatar
Marky Marky is offline
 
Join Date: Aug 2004
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:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

For example, when creating a template called 'booyar' and you use $booyar to call the template, you can add a plugin with:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Hehe
Nice tutorial
Good job ^_^
Reply With Quote
  #6  
Old 25 Jan 2006, 19:10
CyberRanger's Avatar
CyberRanger CyberRanger is offline
 
Join Date: Mar 2004
Originally Posted by princeton
$actiontemplates are templates loaded when a specified action is called such as $do (e.g. ?do=edit)
I can't seem to get the right hang of this. If my script has different templates for different do actions (say ?do=edit, ?do=file, ?do=event, etc) how do I write the actiontemplates statement?
Reply With Quote
  #7  
Old 25 Jan 2006, 19:16
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Real name: Joe Velez

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
Latest Articles:
Liquid Layout = Less Ad Revenue?
How to Monetize Your Site
Improve Web Page Performance
How To Write For The Web


If it needs instructions, there's room for improvement.
Give users what they actually want, not what they say they want. And whatever you do, don't give them new features just because your competitors have them!
Reply With Quote
  #8  
Old 25 Jan 2006, 19:19
CyberRanger's Avatar
CyberRanger CyberRanger is offline
 
Join Date: Mar 2004
Originally Posted by princeton
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
Wow ... thanks for the quick reply! So, is the ?do portion ignored or assumed? For example, would ?act=edit, ?act=file, ?act=event be coded exactly the same way?
Reply With Quote
  #9  
Old 25 Jan 2006, 22:54
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Real name: Joe Velez
it should be ?do=edit, ?do=file, ?do=event

if you use anything else cache the template(s) using $globaltemplates
__________________
Latest Articles:
Liquid Layout = Less Ad Revenue?
How to Monetize Your Site
Improve Web Page Performance
How To Write For The Web


If it needs instructions, there's room for improvement.
Give users what they actually want, not what they say they want. And whatever you do, don't give them new features just because your competitors have them!
Reply With Quote
  #10  
Old 26 Jan 2006, 15:08
Chris-777's Avatar
Chris-777 Chris-777 is offline
 
Join Date: Jan 2006
Real name: Chris
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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Would I just add $globaltemplates to the end of that, since it's not really an action template (it just displays thumbnails) or am I way off the mark?
Reply With Quote
  #11  
Old 26 Jan 2006, 15:14
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Real name: Joe Velez
if it's a file add it to $globaltemplates array (found at the top of page):

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
Latest Articles:
Liquid Layout = Less Ad Revenue?
How to Monetize Your Site
Improve Web Page Performance
How To Write For The Web


If it needs instructions, there's room for improvement.
Give users what they actually want, not what they say they want. And whatever you do, don't give them new features just because your competitors have them!
Reply With Quote
  #12  
Old 26 Jan 2006, 15:18
Chris-777's Avatar
Chris-777 Chris-777 is offline
 
Join Date: Jan 2006
Real name: Chris
Well, the template is called by the file, but I'm not sure exactly where to edit the $globaltemplates array itself.

Apologies for noobing up your thread, I've actually wondered how to do this for awhile now.
Attached Files
File Type: php photoplog_thumbs.php (2.9 KB, 21 views)
Reply With Quote
  #13  
Old 26 Jan 2006, 15:24
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Real name: Joe Velez
I don't really know anything about that hack but you can add the template to the cache_templates hook (plugin):
$globaltemplates[] = 'adv_portal_photoplog_thumbs';

I recommend adding some kind of condition to it.

Have you tried asking the author of the hack? It could just be something that he overlooked.
__________________
Latest Articles:
Liquid Layout = Less Ad Revenue?
How to Monetize Your Site
Improve Web Page Performance
How To Write For The Web


If it needs instructions, there's room for improvement.
Give users what they actually want, not what they say they want. And whatever you do, don't give them new features just because your competitors have them!
Reply With Quote
  #14  
Old 26 Jan 2006, 15:30
Chris-777's Avatar
Chris-777 Chris-777 is offline
 
Join Date: Jan 2006
Real name: Chris
Yeah, I posted in his thread, I'm just trying to do it myself so that I know how in the future. I didn't even think of just adding it to the hook. Thanks man.
Reply With Quote
  #15  
Old 28 Jan 2006, 20:04
rom56 rom56 is offline
 
Join Date: Sep 2004
Real name: Romain
the geek articles use the template cache, i have make a mistake in my modification but i can edit it :s where can i delete this template cache ?
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

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
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 20:48.

Layout Options | Width: Wide Color: