![]() |
[VB4] Use a Varible in a template WITHOUT registering it!
Before I "properly' learned how to preregister variables and custom templates in a default vBulletin template, I had no clue how to use all the custom code I had developed for my site on the standard pages my members would use. I figured out a quick and handy workaround to registering a new template just for a quick variable to display something on a standard page, or to use for a if condition.
First off: Create a plugin in the appropriate place. Example: I have custom forms for my members to use in appropriate threads that are a little different than simply replying, so I need to keep the new reply button as is, and I add an additional button next to it. In this case I used the postbit_display_complete hook (also added an if($post['parentid'] == 0) condition since I used a query in the plugin and didn't want the query called during EVERY post in that thread, and for some reason I could never get it to work with a showthread hook). Now, all variables you decide this plugin will be putting on the vBulletin page must get on somehow, and it had to be a registered variable or template preregistered to be able to be accessible to the template, this hasn't changed. So how do you get around this? The trick: use a variable ALREADY registered!! You have a few available to you almost everywhere anyways: $post, $thread, and $userinfo, to name a few. Simply add the important information to a array key or an array merge as we will be doing below, and you can use like any other variable in that array! Heres an example of code that could work for you: Plugin: postbit_display_complete hook PHP Code:
To use in a template now: Template: SHOWTHREAD HTML Code:
<div id="above_postlist" class="above_postlist"> Hopefully this may help some of you have an easier way to upgrade from VB3, or use in a quick and dirty edit if coding design/portability does not concern you. |
It is bad practice to piggyback your stuff on existing variables. Learn how to properly register them (it's not that hard) instead of starting to do it the wrong way.
BTW, $thread of $post-variables are by no means available almost everywhere. |
I'm totally in agreement with that :)
That was why i said 1. It was before I learned the proper way, and 2. only real usage I can see is a quick and dirty edit where there is no concern about portability or proper code structure. I definitely wouldn't recommend it as a long term fix for an important page of your site or a bigger hack/project. As far as the arrays chosen, I only used those as an example, $user and $phrase would be a little more broad if you want more availability ;) |
All times are GMT. The time now is 11:57 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|