vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=326943

Make array usable in template
by BulliM
05 Dec 2018 15:03

I need an array of userids in template "conversation_userinfo". This array is written in a html or php file.

HTML-File: 1,2,3,4....
PHP-File:echo array(1,2,3,4...);

It should be used like:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

How can I get and set that array as $arrayofuserids in template "conversation_userinfo" ?

noypiscripter 05 Dec 2018 20:40

Try this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


BulliM 06 Dec 2018 10:20

Hey noypiscripter,

thanks, but this is not, what I ask for. I ask for an example, how to get the array from file into a variable in template. I set a hook:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Normally, I would expect variable $arrayofuserids is available in template, but is not. Don't know why. May I use the wrong hook (conversation_before_display_controls) ?

shka 06 Dec 2018 10:30

You have to register your variable for your template (or register global)

In vB4 you can

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Is vB5 the same syntax?
http://vb5support.com/resources/api/...ethod_register

BulliM 06 Dec 2018 10:35

Here: https://www.vbulletin.com/docs/html/..._externalfiles they say it is needed on 4+. Logic, 5>4.

I'll try.

EDIT: I get no result. Neither for {vb:raw $arrayofuserids} nor {vb:raw arrayofuserids}

shka 06 Dec 2018 11:08

Try {vb:debugvardump $arrayofuserids}

BulliM 06 Dec 2018 11:10

Result: NULL

shka 06 Dec 2018 13:00

Ok, my mistake. It seems that vB5 doesn't have a plugin/hook system like vB4. The hooks you see are template hooks, you need php hooks.

For my addons I use only api extensions
Simple example:
- create in /forum/core/packages a subdir /testimportarray/api
- create a file arr.php

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The subdir name /testimportarray has to be the same as in class TestImportArray_Api_Arr and public $product = 'testimportarray';
The subsubdir name /api is repeated in class TestImportArray_Api_Arr
The filename arr.php has to be the same like in class TestImportArray_Api_Arr

Then check in AdminCP/Add-ons & Hooks/Api Extensions and PHP Hooks if your Api is listed without error


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Then you can use the api function getArray in each template

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


BulliM 06 Dec 2018 13:03

I'll try that tomorrow. Thank you.

noypiscripter 07 Dec 2018 01:22

Quote:

Originally Posted by BulliM (Post 2597678)
Here: https://www.vbulletin.com/docs/html/..._externalfiles they say it is needed on 4+. Logic, 5>4.

vB4 mod system != vB5 mod system, so that isn't logically always true.

Anyway, follow what @shka suggested which is using API extensions. An alternative is to use frontend controller. Frontend controller functions are also accessible from the template. But using API extensions is cleaner and more elegant.

delicjous 07 Dec 2018 04:40

If you use a new API like ARR, make it your own API and don't extend it.
You could extend API like Page, Node, User... but why your own?!


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

There is a working example-mod here: https://vbulletin.org/forum/showthre...light=skeleton

BulliM 07 Dec 2018 04:55

Quote:

Originally Posted by shka (Post 2597682)
...

It works like a charm. Thank you shka! Thank to all!

--------------- Added 07 Dec 2018 at 05:41 ---------------

One problem left. Why I cannot use that array in a condition?


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Result:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


But...


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

...works not.

Solved. My solution:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Works, but isn't quite elegant. If there is a better way, I would be interested in. I want that array of userids also global. No need, to load on every post.

shka 07 Dec 2018 06:06

Von hinten durch die Brust :D

BulliM 07 Dec 2018 06:08

Quote:

Originally Posted by shka (Post 2597693)
Von hinten durch die Brust :D

Ja, voll. Die vB-Templates nerven ganz schön. Das dauert noch, bis ich das kann.

delicjous 07 Dec 2018 07:53

Dein Array-Inhalt sind strings. Du benötigst aber int.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

liefert mir


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

und dann funktioniert es.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Deine Funktion sollte public function und nicht public static function sein.


All times are GMT. The time now is 05:41.

Powered by vBulletin® Version 3.8.14
Copyright © 2021, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.