Jump to content

Template hooks - vBulletin 4


Marc
 Share

Recommended Posts

Thought since there are a few conversations about forums on here I would add a bit about vbulletin and template hooks.

 

 

WHAT IS A TEMPLATE HOOK?

 

A template hook is a place within the template code where you can 'hook' your own template code in. You can do this either by inserting the contents of one of your own templates, or simply by inserting your own html in there.

 

 

HELLO WORLD

 

As with any tutorial, its only fair we start off with hello world in the traditional fashion. So lets start shall we, and we can see just how easy it is for you to enter code into your templates by use of template hooks. I am going to do this in a way which shows the basics of creating a vbulletin product so that it starts you off in the right direction

 

 

Step 1: First you will need to create yourself a product. In your admincp go to "plugins & products>Manage Products". At the bottom of the page you will find "Add/Import Product". Click this and you will be presented with the following page:

 

post-952-0-58873800-1339010362_thumb.jpg

 

Choose a productID that will be unique to your product. In this case we will use dbtutorialhelloworld (note all lower case as it has to be, the image above was incorrect lol). Fill in the rest as above.

 

Step 2: We now need to find where we would like to add our code onto the page. For this example we will add the words "Hello World" just above the forums on the forum home page. You will see in various templates, code similar to {vb:raw template_hook.forumhome_above_forums} . This is the one we will use. This is the templatehook forumhome_above_forums and is in the location we would like to place our HTML.

 

Step 3: Now we have located where we would like to add our code and found the template hook name, we can create a plugin to go with our product. Click on "Plugins & Products>Add New Plugin" and you will be presented with a page similar to the following:

 

post-952-0-55254300-1339011042_thumb.jpg

 

First of all we need to select which product we want to associate this plugin with. In this case it is the product we have just created above.

 

Next is one of the important things, the hook location. This is the code hook location which choses when the code you are about to enter will be executed. As we are entering a template hook we want to our code to be entered when the templates are being parsed ready to be entered onto the page. Therefore we can use the "parse_templates" hook location.

 

Title. This is a descriptive title for your plugin so that you can identify it once it is saved. We will call this "Our template hook".

 

Execution order states in which order the hook will be compiled if we happen to have more than one in the same location. You can leave this at whatever it happens to be for this tutorial.

 

Now come the fun part, entering your template hook code!!! Think this part is gonna be hard? Sorry, its not :)

 

$template_hook['forumhome_above_forums'] .= '<p>HELLO WORLD</p>';

 

All you are doing above is adding to the template hook your own code. The varable $template_hook['forumhome_above_forums'] will contain any code added by any other plugins, so you are simply appending that with anything you would like to add. Anything within this variable is added to the page at runtime during the relavant event. In this case the parse_templates event. You finished plugin should look something like this

 

post-952-0-36308100-1339011751_thumb.jpg

 

Mark your plugin as active below the code and click save. You should have something like the below screenshot.

 

post-952-0-08267100-1339011696_thumb.jpg

Edited by Marc
Link to comment
Share on other sites

No it cannot.

 

MyBB is currently going through a massive change after it's slightly breach in security. One of it's changes is that it is moving its MediaWiki to GitHub Pages. These are the pages you need to create an app for MyBB.

Link to comment
Share on other sites

No it cannot.

 

MyBB is currently going through a massive change after it's slightly breach in security. One of it's changes is that it is moving its MediaWiki to GitHub Pages. These are the pages you need to create an app for MyBB.

 

MyBB not support plugin code then Thomas? Never looked into how it works

Link to comment
Share on other sites

Never looked into it, however directly the same thing won't work as it's 2 very different software.

 

Ah sorry I see what ya mean now. May have a look into it once I have done ones for xenforo and IPB. Never looked at MyBB however so bare with me :) Its actually quite handy for myself to do tutorials like this as it means I think about things and how they are supposed to be done :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...