XF 1.5 Looping trough results provided by a class in a template

Liquor

New member
Hi,

I am extremely new to Xen Foro development process, but from what I have gathered my approach should have worked, can anyone of you point out what mistakes have I hit here?

I keep getting errors regarding
--> The following templates contained errors and were not saved: sidebar_game_server_info: Line 10: Template syntax error.
I reviewed the syntax I see no problems, backwards engineering it I hit that the initial error occurs on the for-each so my assumption is that I am not doing the for-each correctly.

Thank you ever so much ;)



Class: Positivus_Html_Sidebar_Game_Status
File: library/Positivus/Html/Sidebar/Game/Status.php
https://pastebin.com/76FCrDjK

Template: New template included within sidebar
https://pastebin.com/cgfWHEzT
 
Great, good to know about that one!
Now it is crying about my variable stating that it not referenced,

The following templates contained errors and were not saved: sidebar_game_server_info: sidebar_game_server_info - Line 17: Invalid variable reference.

line 17:
<div class="server-status-players">{$server.players}</div>

I have given it in the foreach as the value key & it does have a players key
 
Right.. Just read through the raw source code of template compiler for foreach tag. apparently, my would not work unless my class was in direct implement with the array Assoc, as the compiler uses conversion to for instead of foreach.

If I declare say the following:
Code:
foreach(MyClass::StaticResult() as $something){
Then the compiler would interpret it as follows
Code:
for($i=0;$i<count(MyClass:StaticResult();$i++){
$something = MyClass:StaticResult()[$i];

This would not work unless the class is associated with the ArrayAssoc class, which is fine it could be done, but then looking further it seems that it needs to have a direct reference to the variable, so I guess the only way to loop through stuff is to define a variable before looping.

So the answer to my own question lol
Code:
		<xen:set var="$serverList">Positivus_Html_Sidebar_Game_Status::getServers()</xen:set>
		<xen:foreach loop="{$serverList}" value="$server">
fixes the issue
 
Top Bottom