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: |
#32
|
||||
|
||||
this help a lot thanks
|
#33
|
|||
|
|||
Can these instructions be take a little further so the following can be done. When making a template, can that template include a variable that can be entered somewhere in the admincp? For example I want the temple to show "THIS". The only thing is I do not want to go to the template all the time and edit "THIS". Can I make a little addition to the admin CP so I can specify what "THIS" is?
Also, can all these template hooks, templates and all related to me showing "THIS" be saved in one package like a mod is so It can be uploaded to another forum easily? Thanks |
#34
|
||||
|
||||
Thanks for this guide. Indeed good tutorial.
I've crossed into weird thing though (vbulletin version 3.8.2), maybe someone came aross it & can give few tips on what i could have missed - i can't get rid of "uncached template" warning eventhough I have plugin on "cache_templates" adding it to $globaltemplates[], so not sure what am i missing. |
#35
|
|||
|
|||
what hook are you using and whats the plugincode?
nobody can help you without that infos |
#36
|
||||
|
||||
2 plugins:
1] location: "global_start" name: "alt_lp_template" with followign code: PHP Code:
name: "Tempalte Cache" with followign code: PHP Code:
Note this template was added to master style. EDIT: what's more weird, i know it's cached, as later on i can access it from $vbulletin->templatecache['alternate_view'] |
#37
|
|||
|
|||
You have to make it this way:
to cache it: PHP Code:
PHP Code:
|
#38
|
||||
|
||||
thanks, that solved it, wrote under cache name the var name instead... silly me
|
#39
|
|||
|
|||
Excellent Post. Including my Javascript php file worked in parse_templates rather than cache_templates.
|
#40
|
|||
|
|||
Hi Everyone,
Lets say I set some variable: $domain = "testsub.domain.com"; from within a global_start plugin. SHOULD I be able to use this in any template?? I seem to have very mixed results. Some pages with links that contain this domain are just broken... Any ideas? |
#41
|
|||
|
|||
No, some templates are called from functions/methods, so you would have to create plugins to make your variable in the scope there.
You could write your variable into $vbulletin['myvarname'] = 'foo.bar.tld'; because $vbulletin should be everywhere in the scope. I hope you can understand what i mean |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|