vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=104532

How-To Cache Templates
by Princeton
05 Jan 2006 16:46

2 Attachment(s)
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:
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.


PennylessZ28 23 Jan 2006 22:52

Good info, most people dont' follow these rules.

Princeton 23 Jan 2006 23:30

gracias seņor...

feedback is always good and I do appreciate it

Snake 24 Jan 2006 00:59

Thanks for the tutorial!

Marky 24 Jan 2006 19:40

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 ^_^

CyberRanger 25 Jan 2006 19:10

Quote:

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?

Princeton 25 Jan 2006 19:16


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


CyberRanger 25 Jan 2006 19:19

Quote:

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?

Princeton 25 Jan 2006 22:54

it should be ?do=edit, ?do=file, ?do=event

if you use anything else cache the template(s) using $globaltemplates

Chris-777 26 Jan 2006 15:08

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?

Princeton 26 Jan 2006 15:14

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.


Chris-777 26 Jan 2006 15:18

1 Attachment(s)
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. ;)

Princeton 26 Jan 2006 15:24

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.

Chris-777 26 Jan 2006 15:30

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

rom56 28 Jan 2006 20:04

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 ?


All times are GMT. The time now is 16:33.

Powered by vBulletin® Version 3.8.13
Copyright © 2019, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.