Register Arama Bugünkü Mesajlar Tüm Forumu Okundu Say

Reply
 
Thread Tools
[VB4] Use a Varible in a template WITHOUT registering it!
vB.Org Poster
vB.Org Poster has disabled reputation
Kayıt Tarihi: Jul 2018
Mesajlar: 298

Show Printable Version Email this Page
Makale: vBulletin 4 Makaleleri, yazan vB.Org Poster 09 Jul 2018, 23:27

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

Kod Blok Kilitli:      (Kayıt veya giriş yapmalısın)  
Engellenmiş, kayıtlı olmayan veya onay bekleyen kişiler kodlara erişemezler.

Now my particular table saves info including a threadid for each entry, hence why I used that as the WHERE condition, that isn't necessary, just as an example. As you can see though, we now have ALL information from the row in that table that has that threadid. I also have a 1 row limit on that condition to avoid a possible issue, but more rows would be fine provided you used a while loop to assign the information before merging your information. This also MUST be an array you use, so either use the query array, or cast the variable into an array, etc.

To use in a template now:
Template: SHOWTHREAD

Kod Blok Kilitli:      (Kayıt veya giriş yapmalısın)  
Engellenmiş, kayıtlı olmayan veya onay bekleyen kişiler kodlara erişemezler.

It's that simple! As you can see I have used both in a vb:if condition AND as a vb:raw array key, so it can be useful either way!

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.
Views: 32
Reply With Quote
Reply

Thread Tools

Şunları Yapabilirsin
Yeni Konu Açmak
Konuya Cevap Yazmak
Eklenti Eklemek
Düzenleme Yapabilmek

Forum Atla


LD'de Yeni misin? Yardıma mı ihtiyacın var?

All times are GMT +3. The time now is 23:54.

Tasarım Özelliği | Genişlik: Geniş Renk: [VB4] Use a Varible in a template WITHOUT registering it! [VB4] Use a Varible in a template WITHOUT registering it! [VB4] Use a Varible in a template WITHOUT registering it! [VB4] Use a Varible in a template WITHOUT registering it! [VB4] Use a Varible in a template WITHOUT registering it!