Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles

Reply
 
Thread Tools
How To Include A Custom Template Via Plugins
peterska2
Join Date: Oct 2003
Posts: 6,504

 

Manchester, UK
Show Printable Version Email this Page Subscription
peterska2 peterska2 is offline 06-29-2006, 10:00 PM

This tutorial will show you how to include custom templates within your vBulletin pages using plugins.

First of all, you need to create your custom template. Lets call this mytemplate for the sake of this tutorial.

Once you have created your template, and decided where you would like to have it placed, you can put the template variable $mytemplate there.

As vBulletin does not yet know what to do with this template variable, it simply ignores it when generating the page.

Next you need to create the plugins for the template, so that vBulletin knows what to do with it. You need to create two plugins, one to include the template, and one to cache it (saves a query).

The easiest way to do this, although not technically the best, is to create the first plugin in either the hook location global_start or parse_templates This allows the template to be used globally throughout your site. However, you can also create this plugin in the _complete hook for the location that you wish to have it displayed (eg postbit_complete memberinfo_complete etc).

The content of this first plugin will be as follows:
Code:
eval('$mytemplate = "' . fetch_template('mytemplate') . '";');
This tells it that when it comes across $mytemplate, it is to fetch the template mytemplate and include it there. This plugin can be named anything that you want, and should be set to active.

The second plugin is always placed in the hook location cache_templates as this is the one that literally does what it says on the tin. It caches the template, preventing an extra query on each page that it is included on.

The content of this plugin will be as follows:
Code:
$globaltemplates = array_merge($globaltemplates, array('mytemplate'));
This tells it to add mytemplate to the global templates array, which ensures that everywhere that it is used, it is cached. Again, this plugin can be named anything that you want, but not the same as the first one, and should be set to active.


Congratulations, your custom template is now included on your site without the need for any code modifications, and is already up and running.

If at any point you decide that you want to remove the custom template, either temporarily or permanently, you can simply disable the two plugins and it will again vanish.


My personal preference is to use the parse_templates hook for the first plugin as this enables the template to be used on every page on your site so you can move it about without having to edit the plugin. It is also useful if you wish to have it included on two or more pages.


The method explained in this tutorial is the exact same method as I have used for the following modifications:
Reply With Quote
  #22  
Old 01-06-2008, 08:54 PM
siliconfinance siliconfinance is offline
 
Join Date: Mar 2007
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

didn't work for me in 3.6.8
Reply With Quote
  #23  
Old 06-13-2008, 01:16 AM
Jhonnyf's Avatar
Jhonnyf Jhonnyf is offline
 
Join Date: Nov 2007
Location: In my mind
Posts: 196
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

then.. if I want to use a Custom Templare, I should make all that ceremony?
Reply With Quote
  #24  
Old 10-15-2008, 08:08 PM
sarahk's Avatar
sarahk sarahk is offline
 
Join Date: Jun 2004
Location: Auckland, New Zealand
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Kerry-Anne

My template will have a few variables generated for it. Which plugin carries the code to process them?
Reply With Quote
  #25  
Old 12-06-2008, 01:29 AM
Varsh's Avatar
Varsh Varsh is offline
 
Join Date: Aug 2006
Location: UK
Posts: 98
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Paul M View Post
You shouldn't be merging arrays for this, that's very wasteful of resources, just add to the array ;

PHP Code:
globaltemplates[] = 'mytemplate'
This I got errors with due to an unexpected "[". If it worked then this would've been the ideal statement to use. Has anyone else had this issue on vB3.8x?
Reply With Quote
  #26  
Old 01-12-2009, 07:18 AM
vietfancy's Avatar
vietfancy vietfancy is offline
 
Join Date: Feb 2005
Posts: 278
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it should be:

PHP Code:
$globaltemplates[]='mytemplate'
Reply With Quote
  #27  
Old 01-15-2009, 07:30 PM
Gulf Soul Gulf Soul is offline
 
Join Date: Jul 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello

I need a code which i forgot. ill try try to explain it.
for e.g.
If i wanted to add the line aaa under the line yyy in the footer or forumhome.
what could shall i use??

thanks
Reply With Quote
  #28  
Old 03-15-2009, 06:50 PM
alexpaterson alexpaterson is offline
 
Join Date: Mar 2009
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi, I'm in the same position,

I can't get my own variable content to show in the template.

Is there a template variable assignment statement , like in smarty ?


Alex
Reply With Quote
  #29  
Old 03-17-2009, 05:37 PM
alexpaterson alexpaterson is offline
 
Join Date: Mar 2009
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I got this working OK, I just declared the variable assignments in the global_start hook, so it was in scope for the entire board.

Thanks to Kerry-Anne for posting this, it saved me lots of time.
Reply With Quote
  #30  
Old 03-19-2009, 08:14 AM
Come2Daddy Come2Daddy is offline
 
Join Date: May 2008
Posts: 128
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this is exactly, what I'v been wondering about

thanx a lot
Reply With Quote
  #31  
Old 03-21-2009, 10:24 AM
Hitterman's Avatar
Hitterman Hitterman is offline
 
Join Date: May 2008
Location: Tutorialistic.net
Posts: 172
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This was really extrmely helpful. Thanks a lot.
Reply With Quote
Reply

Thread Tools

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 08:56 AM.


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.04629 seconds
  • Memory Usage 2,293KB
  • Queries Executed 25 (?)
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_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
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (4)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete