The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
[vBulletin|PHP|HTML]Automatic Template Edits
You are creating a new vBulletin product and want to make it more user friendly so that the users don't have to edit the templates manually?Then this tutorial will point you the right way.Basically the code I am going to demonstrate simply finds a specific part of a template and inserts our code/template into it. Ok let's say you have a template or a piece of html code you want to include somewhere: HTML Code:
<em>My name is $name and welcome to $board</em> 1. Insert the code into a template and then insert the whole template into the site. So you now have the html code in your template called TEMPLATE.I suggest you cache it for faster loading.To do that create a new plugin on the cache_templates hook with this content: PHP Code:
So now what we just need to do,is insert our template into another one.To do that you need to know what page you want to display it on,the hooks that are located on that page and the templates called.In the template you will add the code in find a block of code that is static,thus won't ever be changed (like html comments).Should be one liner.Our template is TEMPLATE and the one that will include it is MAINTEMPLATE. Then use this phpcode. PHP Code:
To include a code on every page use the hook global_start and the template header,footer or headinclude DONE 2. Insert the code into a variable and insert it via replace. Ok this is a bit easier than the code above.So we still want to add the code but don't want a template?Make the code into a variable. PHP Code:
Then just use the code before. PHP Code:
3. Insert the code into a variable and call the variable in the template. This is the easiest way.So we have $template already specified and we just put the variable ($template) into any template and vBulletin will parse it .But you have to make sure that the hook the variable is on,is called on that page! DONE 4. Attach code to an existing variable in the template. This method became easier when vBulletin introduced template hooks. For instance,open template navbar and you can find $template_hook['navbar_buttons_left'] somewhere in the code,thanks to which you can add new navbar buttons simply using plugins.To do that,I make a new plugin on global_setup_complete (or any plugin called where the variable is) and add this code: PHP Code:
You can also attach a whole template this way.In the next example I added my template below navbar. PHP Code:
I hope this article has helped you understand this topic and develop better and more user friendly products! |
#12
|
||||
|
||||
Making your end users do less and less creates the problems we have now. Make your users do the template edits.
|
#13
|
||||
|
||||
Quote:
I for one have a hack (CYB - Forum Rules) and he has done this, He have placed the link to the forumrules in my navbar, and I can't change it, or the location of it. Think that's fun when you want to make a custom style? For one: If I change my navbar to the header, that link does not follow.. and so on. Bad, bad, bad bad bad bad bad bad. |
#14
|
||||
|
||||
Whether you like automatic editing of templates is a personal choice, not a fact. If you want to discuss the merits of doing it please start a new thread, not clutter up this one.
|
#15
|
||||
|
||||
Quote:
|
#16
|
||||
|
||||
Nicely done Ziki. And as an extra bonus, something I just found out. Namely that you don't need to create or insert a template if all you want to insert is one value from your settings.
Code:
$str = 'findthis'; $vbulletin->templatecache['footer'] = str_replace($str,$str.$vbulletin->options['kerjigger'],$vbulletin->templatecache['footer']); Code:
if ($vbulletin->options['mysetting']) { $str = 'findthis'; $vbulletin->templatecache['footer'] = str_replace($str,$str.$vbulletin->options['kerjigger'],$vbulletin->templatecache['footer']); } |
#17
|
||||
|
||||
Two small additional notes.
Firstly, templatecache identities are CASE SENSITIVE. So $vbulletin->templatecache['SHOWTHREAD'] will work but $vbulletin->templatecache['showthread'] will not, because the the template is named with capitals. Secondly, if you are doing a find/replace it's slightly more efficient to include what you're finding in the replacement text instead of appending it in the str_replace. So Code:
$find = 'this'; $replace = 'this that'; $vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $replace, $vbulletin->templatecache['SHOWTHREAD']); Code:
$find = 'this'; $replace = ' that'; $vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $find.$replace, $vbulletin->templatecache['SHOWTHREAD']); |
#18
|
|||
|
|||
there is a very nice product from andreas http://www.vbhacks-germany.org/showthread.php?t=5572
|
#19
|
|||
|
|||
Didnt read, but ALL mods should use this! :P I hate editing templates for mods, it means you gota do it for every style, i have alot of styles =/
|
#20
|
||||
|
||||
Article was updated.
|
#21
|
||||
|
||||
Updated
|
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|