Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 05 Dec 2018, 15:03
BulliM's Avatar
BulliM BulliM is offline
 
Join Date: Oct 2017
Make array usable in template

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" ?
Reply With Quote
  #2  
Old 05 Dec 2018, 20:40
noypiscripter's Avatar
noypiscripter noypiscripter is offline
 
Join Date: Aug 2013
Try this:

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

__________________
Glenn Vergara, an ex-vB Developer, now a vB Mod Developer

GIPHY for vB5 | AutoLinker | Video Attachments Player | New Registered Users Module | Clear System Cache Cron | DragNDrop Upload | Topic AJAX AutoUpdate | Force Read Topic
Reply With Quote
  #3  
Old 06 Dec 2018, 10:20
BulliM's Avatar
BulliM BulliM is offline
 
Join Date: Oct 2017
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) ?
Reply With Quote
  #4  
Old 06 Dec 2018, 10:30
shka shka is offline
 
Join Date: Mar 2016
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
Reply With Quote
  #5  
Old 06 Dec 2018, 10:35
BulliM's Avatar
BulliM BulliM is offline
 
Join Date: Oct 2017
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}

Last edited by BulliM; 06 Dec 2018 at 10:55.
Reply With Quote
  #6  
Old 06 Dec 2018, 11:08
shka shka is offline
 
Join Date: Mar 2016
Try {vb:debugvardump $arrayofuserids}
Reply With Quote
  #7  
Old 06 Dec 2018, 11:10
BulliM's Avatar
BulliM BulliM is offline
 
Join Date: Oct 2017
Result: NULL
Reply With Quote
  #8  
Old 06 Dec 2018, 13:00
shka shka is offline
 
Join Date: Mar 2016
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.

Reply With Quote
  #9  
Old 06 Dec 2018, 13:03
BulliM's Avatar
BulliM BulliM is offline
 
Join Date: Oct 2017
I'll try that tomorrow. Thank you.
Reply With Quote
  #10  
Old 07 Dec 2018, 01:22
noypiscripter's Avatar
noypiscripter noypiscripter is offline
 
Join Date: Aug 2013
Originally Posted by BulliM View Post
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.
__________________
Glenn Vergara, an ex-vB Developer, now a vB Mod Developer

GIPHY for vB5 | AutoLinker | Video Attachments Player | New Registered Users Module | Clear System Cache Cron | DragNDrop Upload | Topic AJAX AutoUpdate | Force Read Topic
Reply With Quote
  #11  
Old 07 Dec 2018, 04:40
delicjous's Avatar
delicjous delicjous is offline
 
Join Date: Nov 2014
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
__________________
vBulletin-Forum.de closed!
Reply With Quote
  #12  
Old 07 Dec 2018, 04:55
BulliM's Avatar
BulliM BulliM is offline
 
Join Date: Oct 2017
Originally Posted by shka View Post
...
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.

Last edited by BulliM; 07 Dec 2018 at 06:11.
Reply With Quote
  #13  
Old 07 Dec 2018, 06:06
shka shka is offline
 
Join Date: Mar 2016
Von hinten durch die Brust
Reply With Quote
  #14  
Old 07 Dec 2018, 06:08
BulliM's Avatar
BulliM BulliM is offline
 
Join Date: Oct 2017
Originally Posted by shka View Post
Von hinten durch die Brust
Ja, voll. Die vB-Templates nerven ganz schön. Das dauert noch, bis ich das kann.
Reply With Quote
  #15  
Old 07 Dec 2018, 07:53
delicjous's Avatar
delicjous delicjous is offline
 
Join Date: Nov 2014
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.
__________________
vBulletin-Forum.de closed!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 21:07.

Layout Options | Width: Wide Color: