The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
How To Include A Custom Template Via Plugins
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') . '";'); 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')); 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: |
#12
|
|||
|
|||
Do you need the first plugin as well when using that code Paul?
I'm actually trying to do this... My goal is to have a template custom_header with a variable $custom_header which will contain all of the code from $header with a slight change (removing code for a right column and a different logo) for a CMPS home page... 1.) I do add new template, and put the code I want in it, saving it as custom_header. It now appears under "Custom Templates" 2.) I make a plugin with Quote:
3.) I add the plugin "globaltemplates[] = 'custom_header';" starting in cache template I enable both. I get error:Parse error: syntax error, unexpected '[' in /home/uninsta1/public_html/bu/forums/global.php(346) : eval()'d code on line 55 Right above the logo in ALL pages (not just CMPS...) Shortly thereafter forums don't show and errors occur in functions.php as well. I disable plugins. What should I try next? |
#13
|
|||
|
|||
if you don't put $ before globaltemplates[], that won't work...
|
#14
|
|||
|
|||
Oh god, this is confusing. Is there any way of explaining this to someone illiterate in the technical coding world?
I want to incorporate my custom template into the forum and $mycustomtemplate isn't working. Edit: Sorry for this post, I am an idiot. Worked it out. GREAT tutorial, this is EXACTLY what I was looking for ^_^ |
#15
|
|||
|
|||
Quote:
A followup please: what exactly is "the technically best" way to do it? Thanks. |
#16
|
|||
|
|||
I have this working completely, except in my hook I have $myvar = "test";
Now in my header template I have : $myvar Nothing happens. how can I get $myvar to be replaced with the dynamically created value from the hook? |
#17
|
||||
|
||||
Compliments to Kerry-Anne for posting this.
I'm new to vB, but a long time PHP guru and forum admin (including uBB and phpBB). After reviewing some of the replies here I wish to add that the information presented here is not simply copy/paste, and requires basic knowledge of PHP as well as the hook and template system of vB. I noticed some of the more experienced PHP developers making suggestings and fixes here. I concur and wish to expand on that. I tried the procedure, and with a few minor corrections got it to work with less overhead simply by optimizing the commands (using advice posted earlier plus new advice from me): I can sum it up in 4 easy steps (vb 3.6.7+): 1) Create a custom template, i.e. "mytemplate" for purposes of these instructions Put in there "Hello World!" or any HTML so you know its working when it displays. 2) Add a new plugin, suggested name is "mytemplate_plugin" for easy reference Pick hook as "global_start" if you want your template available in any other, or select the appropriate hook depending on where you want your template to display. The latter is the better choice if you are customizing a specific feature of vB. Set plugin PHP code: $mytemplate_plugin = fetch_template('mytemplate_plugin_home'); 3) Create another plugin, suggested name is: "Cached - mytemplate_plugin" Pick hook as "cache_template" (located within vBulletin; General hooks in pulldown) Set plugin PHP code: $globaltemplates[]='mytemplate_plugin'; 4) In whatever template you wish (based on step 2) place the variable $mytemplate_plugin where you want your custom template to display. If successful, you'll see your "Hello World!" or your HTML as in step 1. Folks, that's all there is to it. Notice no need for eval or array_merge. This approach follows a simple naming convention that's easy to understand long after you implement and forget, and uses the most efficient PHP to get the job done, and will work perfectly without have to hack any native vB code. Yes, there are a million ways to skin a cat, this is one, but if you start doing alot of customization of this type, keeping the naming convention and optimizing the PHP code will save valuable server resources. Compliments to all who posted. Thanks for your time and if I missed something, please let me know. -jim |
#18
|
|||
|
|||
The original post indicates that by attaching the "eval(.." plugin to the "parse_templates" hook, the template will be available to all other templates. I have not found that to be the case. I made a custom template, followed the above instructions precisely, and tried to use my custom template in FORUMDISPLAY and SHOWTHREAD - neither worked. It does work when I attach it to the "forumdisplay_complete" hook and the "showthread_complete" hook.
I want to be able to eval it in a single plugin, and make that template available to absolutely every other template - is there a way I can do that with a single hook? |
#19
|
||||
|
||||
This is just what i have been looking for. I now have my affiliates on a seperate template from my forum home
|
#20
|
|||
|
|||
Like Jingman stated - none of your solutions working if new template is added to FORUMDISPLAY, no matter of the hook location...
Any other thoughts? Thanks |
#21
|
||||
|
||||
Both Methods, original and that of iVox, seem to make my template appear, however they do not seem to parse the template. I have conditionals in my template, and they appear like ".(($post[field5]) ? (" on the page.
What can be done to fix this? |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|