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: |
#2
|
|||
|
|||
Thank you for this. I've been trying to split up some templates I've changed quite a lot into some easier chunks and wasn't sure how before I read this
One question though, can I use the same plugin to parse multiple templates or do they have to be individual? eg, Code:
eval('$mytemplate = "' . fetch_template('mytemplate') . '";'); eval('$mytemplate2 = "' . fetch_template('mytemplate2') . '";'); Code:
$globaltemplates = array_merge($globaltemplates, array('mytemplate')); $globaltemplates = array_merge($globaltemplates, array('mytemplate2')); |
#3
|
|||
|
|||
Yes that will work, however for the second one
Code:
$globaltemplates = array_merge($globaltemplates, array('mytemplate', 'mytemplate2')); |
#4
|
|||
|
|||
ah, thank you I hadn't realised that.
|
#5
|
|||
|
|||
Question what if I wanted to replace a template al together?
Lets say, instead of calling forum_home, i want a plugin that will call forum_new instead ?? |
#6
|
|||
|
|||
You would need to put a conditional in your forumhome template so that if the plugin was enabled then it would use the forum_new, and if it wasn't, or some other condition, then it would use forum_home
|
#7
|
|||
|
|||
I've been trying to add a template in part of the forumhome_forumbit_x templates and it's not working. I've followed the instructions above (adding the parse plugin to parse_templates). I've also tried it out by adding it to another template such as the footer and it appears. Are there some templates that can't have another template added inside them?
|
#8
|
||||
|
||||
You shouldn't be merging arrays for this, that's very wasteful of resources, just add to the array ;
PHP Code:
|
#9
|
|||
|
|||
Quote:
|
#10
|
|||
|
|||
Quote:
[] adds to the end of the array |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|