![]() |
|
Thread Tools |
#1
|
||||
|
||||
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:
How can I get and set that array as $arrayofuserids in template "conversation_userinfo" ? No members have liked this post.
|
#2
|
||||
|
||||
__________________
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 No members have liked this post.
|
#3
|
||||
|
||||
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:
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) ? No members have liked this post.
|
#4
|
||||
|
||||
You have to register your variable for your template (or register global)
In vB4 you can
Is vB5 the same syntax? http://vb5support.com/resources/api/...ethod_register No members have liked this post.
|
#5
|
||||
|
||||
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} No members have liked this post.
Last edited by BulliM; 06 Dec 2018 at 10:55. |
#6
|
|||
|
|||
Try {vb:debugvardump $arrayofuserids}
No members have liked this post.
|
#8
|
||||||||||||
|
||||||||||||
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
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
Then you can use the api function getArray in each template
No members have liked this post.
|
#9
|
||||
|
||||
I'll try that tomorrow. Thank you.
No members have liked this post.
|
#10
|
||||
|
||||
Originally Posted by BulliM
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 No members have liked this post.
|
#11
|
||||||||
|
||||||||
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?!
There is a working example-mod here: https://vbulletin.org/forum/showthre...light=skeleton
__________________
![]() No members have liked this post.
|
#12
|
||||||||||||||||||||
|
||||||||||||||||||||
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?
Result:
But...
...works not. Solved. My solution:
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. No members have liked this post.
Last edited by BulliM; 07 Dec 2018 at 06:11. |
#13
|
|||
|
|||
Von hinten durch die Brust
![]() No members have liked this post.
|
#14
|
||||
|
||||
Ja, voll. Die vB-Templates nerven ganz schön. Das dauert noch, bis ich das kann.
No members have liked this post.
|
#15
|
||||||||||||
|
||||||||||||
Dein Array-Inhalt sind strings. Du benötigst aber int.
liefert mir
und dann funktioniert es.
Deine Funktion sollte public function und nicht public static function sein.
__________________
![]() No members have liked this post.
|
![]() |
«
Previous Thread
|
Next Thread
»
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|
New To Site? | Need Help? |
All times are GMT. The time now is 16:20.