Marc Posted June 6, 2012 Share Posted June 6, 2012 (edited) 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: 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: 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 Mark your plugin as active below the code and click save. You should have something like the below screenshot. Edited June 6, 2012 by Marc Nathan 1 Quote Link to comment Share on other sites More sharing options...
Thomas Posted June 6, 2012 Share Posted June 6, 2012 You did that on a live forum? Quote Link to comment Share on other sites More sharing options...
Marc Posted June 6, 2012 Author Share Posted June 6, 2012 (edited) No, my development forum Will do one for xenforo and IPB once I set myself a dev forum up for those too Edited June 6, 2012 by Marc Quote Link to comment Share on other sites More sharing options...
tetutato Posted June 6, 2012 Share Posted June 6, 2012 Can we do this with MyBB? D: Quote Link to comment Share on other sites More sharing options...
Thomas Posted June 6, 2012 Share Posted June 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
Marc Posted June 6, 2012 Author Share Posted June 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
Thomas Posted June 6, 2012 Share Posted June 6, 2012 Never looked into it, however directly the same thing won't work as it's 2 very different software. Quote Link to comment Share on other sites More sharing options...
Marc Posted June 6, 2012 Author Share Posted June 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
ridwan sameer Posted June 7, 2012 Share Posted June 7, 2012 MyBB does have the ability to let you code your own plugins. btw nice little article here mate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.