![]() |
|
Article Options |
How-To Cache Templates
Princeton
Join Date: Nov 2001
Posts: 6,693
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
![]() 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:
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:
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:
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
With this new information we fix the uncached issue by adding
below the $actiontemplates array. The final code should look like this:
No members have liked this post.
Last edited by Princeton; 07 Jan 2006 at 14:21.. |
||||||||||||||||||||
Views: 27183
|
Comments |
#2
|
|||
|
|||
Good info, most people dont' follow these rules.
No members have liked this post.
|
#3
|
||||
|
||||
gracias seņor...
feedback is always good and I do appreciate it
__________________
Former vBulletin.org Staff Member 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! No members have liked this post.
|
#4
|
||||
|
||||
Thanks for the tutorial!
No members have liked this post.
|
#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:
For example, when creating a template called 'booyar' and you use $booyar to call the template, you can add a plugin with:
Hehe ![]() Nice tutorial ![]() Good job ^_^ No members have liked this post.
|
#6
|
||||
|
||||
Originally Posted by princeton
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?
__________________
AboutToday - Bring RSS Feeds and Daily Events to Your Site! DownloadsII - Upload files, create categories, link to external files No members have liked this post.
|
#7
|
||||
|
||||
__________________
Former vBulletin.org Staff Member 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! No members have liked this post.
|
#8
|
||||
|
||||
Originally Posted by princeton
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?
__________________
AboutToday - Bring RSS Feeds and Daily Events to Your Site! DownloadsII - Upload files, create categories, link to external files No members have liked this post.
|
#9
|
||||
|
||||
it should be ?do=edit, ?do=file, ?do=event
if you use anything else cache the template(s) using $globaltemplates
__________________
Former vBulletin.org Staff Member 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! No members have liked this post.
|
#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:
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? No members have liked this post.
|
#11
|
||||
|
||||
if it's a file add it to $globaltemplates array (found at the top of page):
__________________
Former vBulletin.org Staff Member 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! No members have liked this post.
|
#12
|
|||
|
|||
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. ![]() No members have liked this post.
|
#13
|
||||
|
||||
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.
__________________
Former vBulletin.org Staff Member 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! No members have liked this post.
|
#14
|
|||
|
|||
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.
![]() No members have liked this post.
|
#15
|
|||
|
|||
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 ?
No members have liked this post.
|
![]() |
«
Previous Article
|
Next Article
»
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Article Options | |
|
|
New To Site? | Need Help? |
All times are GMT. The time now is 01:38.