Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
How-To Cache Templates
Princeton's Avatar
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
Show Printable Version Email this Page Subscription
Princeton Princeton is offline 01-04-2006, 10:00 PM

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

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">
With this new information we fix the uncached issue by adding
PHP Code:
$actiontemplates['insertsettings'] =& $actiontemplates['options']; 
below the $actiontemplates array.

The final code should look like this:
PHP Code:
$actiontemplates = array(
    
'options' => array(
        
'gtblog_options',
        
'gtblog_radio_option',
        
'newpost_errormessage',
    )
$actiontemplates['insertsettings'] =& $actiontemplates['options']; 
Attached Images
File Type: gif 1.gif (18.7 KB, 0 views)
File Type: gif 1a.gif (26.3 KB, 0 views)
Reply With Quote
  #12  
Old 01-26-2006, 01:14 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

if it's a file add it to $globaltemplates array (found at the top of page):
HTML Code:
 $globaltemplates = array(
        'other_templates_here',
        'adv_portal_photoplog_thumbs',
    );
Reply With Quote
  #13  
Old 01-26-2006, 01:18 PM
Guest210212002
Guest
 
Posts: n/a
Default

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, 24 views)
Reply With Quote
  #14  
Old 01-26-2006, 01:24 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #15  
Old 01-26-2006, 01:30 PM
Guest210212002
Guest
 
Posts: n/a
Default

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
  #16  
Old 01-28-2006, 06:04 PM
rom56 rom56 is offline
 
Join Date: Sep 2004
Location: France, bretagne
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
  #17  
Old 01-28-2006, 06:09 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure what you mean. Have you asked the author of the hack?
Reply With Quote
  #18  
Old 01-29-2006, 01:44 PM
netwind netwind is offline
 
Join Date: Feb 2005
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
 eval('$adv_code .= "' fetch_template('adv_creativeSuite') . '";'); 
Reply With Quote
  #19  
Old 01-29-2006, 07:52 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

netwind,
follow the instructions found on this page: https://vborg.vbsupport.ru/showthread.php?t=99132
Reply With Quote
  #20  
Old 03-11-2006, 03:08 PM
puertoblack2003's Avatar
puertoblack2003 puertoblack2003 is offline
 
Join Date: Aug 2005
Location: Philadelphia
Posts: 1,073
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
ok where here do i add the fuction to elimated that uncache...

PHP Code:
switch ($vbulletin->options['mtext_color'])
    {
    case 
0:    $renk 'Dark Red'; break;
    case 
1:    $renk 'Red'; break;
    case 
2:    $renk 'Orange'; break;    
    case 
3:    $renk 'Brown'; break;
    case 
4:    $renk 'Yellow'; break;
    case 
5:    $renk 'Green'; break;
    case 
6:    $renk 'Olive'; break;
    case 
7:    $renk 'Cyan'; break;
    case 
8:    $renk 'Blue'; break;
    case 
9:    $renk 'Dark Blue'; break;
    case 
10:    $renk 'Indigo'; break;
    case 
11:    $renk 'Violet'; break;
    case 
12:    $renk 'White'; break;
    case 
13:    $renk 'Black'; break;
  }

switch (
$vbulletin->options['mtext_direction'])
    {
        case 
0:    $yer 'left'; break;
        case 
1:    $yer 'right'; break;
  }

$Positionx1 '$spacer_open';
    eval(
'$marqtextx = "' fetch_template('Marquee_Text') . '";');
    
$vbulletin->templatecache['header'] = str_replace($Positionx1,$Positionx1.'$marqtextx'  $vbulletin->templatecache['header']); 
thank you
Reply With Quote
  #21  
Old 03-11-2006, 05:00 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

add the template to the cache_templates hook (plugin):
Code:
$globaltemplates[] = 'Marquee_Text';
Reply With Quote
Reply


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


All times are GMT. The time now is 07:24 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05166 seconds
  • Memory Usage 2,349KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (2)bbcode_html
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (3)postbit_attachment
  • (9)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete