How-To Cache Templates
1 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:
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:
|
Good info, most people dont' follow these rules.
|
gracias se?or...
feedback is always good and I do appreciate it |
Thanks for the tutorial!
|
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 ^_^ |
Quote:
|
HTML Code:
$actiontemplates = array( |
Quote:
|
it should be ?do=edit, ?do=file, ?do=event
if you use anything else cache the template(s) using $globaltemplates |
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') . '";'); |
if it's a file add it to $globaltemplates array (found at the top of page):
HTML Code:
$globaltemplates = array( |
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. ;) |
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. |
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. :)
|
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 ?
|
I'm not sure what you mean. Have you asked the author of the hack?
|
princeton This article good for creating stand-alone pages, but I need wrote plugins, wich evalulate templates without modify standart forum code.
How ? PHP Code:
|
netwind,
follow the instructions found on this page: https://vborg.vbsupport.ru/showthread.php?t=99132 |
ok trying to follow this rule but still confused which i'm learning to cache this template because i have this on my forum
Code:
Uncached templates: Marquee_Text (1) PHP Code:
|
add the template to the cache_templates hook (plugin):
Code:
$globaltemplates[] = 'Marquee_Text'; |
Quote:
|
good day,
i using that method to cache template i implented a postbit marqee hack and for some reason that method won't work. Code:
$globaltemplates[] = 'Postbit_Marquee'; thanks in advance. |
I just cant get my head around adding "cache" to a product, to cache the templates.
Will you do me a favour Princeton or anybody else who knows how to do this. Take a look at my product code and add the cache code for me. So I can just paste it back in my XML file. Code:
<?xml version="1.0" encoding="ISO-8859-1"?> |
Thanks for the explanation. It worked for me too.
|
If you have a lot of templates which may not necessarily be used, you can save resources that would be used to cache unneeded templates by instead caching them dynamically based on whether or not they are needed. This does assume a bit of knowledge, but it's commented for clarity.
Let's say you have 10 templates, all of which can be enabled or disabled individually via a yesno option in your plugin. I'll just display 3 for the example. PHP Code:
I would suggest using the microstats plugin to easily check everything is caching as it should. |
I need a little help.
PHP Code:
|
THIS_SCRIPT changes from file to file ...
at the top of any file you will find THIS_SCRIPT defined ... this is the value that needs to be used on the conditional |
I used another plugin to cache this template with this code.
Code:
$globaltemplates = array_merge($globaltemplates, array('quickreply_addon')); |
When writing my plugin code, the following doesn't work in the cache_templates hook (queries still added for uncached templates):
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
Quote:
|
Very useful info. I followed the instructions to remove the uncached ones thx. :cool:
|
i have a php script that i am having trouble with. it is not written for vbulletin, but i would like to include it in my vb's template. this script has about 3-4 php files. i create a php file from which i run my script (followed the instructions from How to create a vbulletin powered page). i only include once the index.php of my script, which runs other php files from inside of it.
my problem is the following: when i run the script, everything is fine, the template is there etc. when i enter the details the script asks for, and i hit submit, the new window that opens does not have the vb template. i've tried everything, no luck. the window that opens when i hit submit has no action (etc. xxx.php?=something.) its just xxx.php. the funny thing is that if i have an error in my form, the template stays as it is even though a new window opens. the problem only occurs when i hit submit. please help :( |
My question is "Why"?
What does caching templates do? What benefit is there for the programmer and the end user? |
Caching templates means that all the templates are fetched with a single query at the beginning of the script, if you fetch un-cached templates during the script the script has to make database queries to fetch it. Thus using server resources that you don't need to.
|
Quote:
Call it PHP Code:
Code:
$globaltemplates[] = 'sidebar'; Thanks :) |
All times are GMT. The time now is 06:50 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|