![]() |
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: Code:
<vb:if condition="in_array($conversation['userid'], $arrayofuserids)">...</vb:if> |
Try this:
Code:
{vb:set arrayofuserids, {vb:php array, 1, 2, 3, 4}} |
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: Code:
ob_start(); |
You have to register your variable for your template (or register global)
In vB4 you can PHP Code:
http://vb5support.com/resources/api/...ethod_register |
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} |
Try {vb:debugvardump $arrayofuserids}
|
Result: NULL
|
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 PHP Code:
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 Code:
Add-on: testimportarray PHP Code:
|
I'll try that tomorrow. Thank you.
|
Quote:
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. |
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?! PHP Code:
HTML Code:
{vb:data userIds, testimportarray:arr, getArray} |
Quote:
--------------- Added [DATE]1544164891[/DATE] at [TIME]1544164891[/TIME] --------------- One problem left. Why I cannot use that array in a condition? Code:
{vb:data arrayofuserids, arr, getArray} HTML Code:
var_dump: $arrayofuserids But... Code:
{vb:data arrayofuserids, arr, getArray} Solved. My solution: PHP Code:
Code:
{vb:data arrayofuserids, arr, getArray} |
Von hinten durch die Brust :D
|
Quote:
|
Dein Array-Inhalt sind strings. Du ben?tigst aber int.
PHP Code:
HTML Code:
var_dump: $array HTML Code:
<vb:if condition="in_array($user['userid'], $array)"> |
Quote:
|
I think the problem with his first try is - his strings are two chars (with \n ?)
He wrotes PHP Code:
|
Quote:
|
All times are GMT. The time now is 01:01 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:
|