MattW
Well-known member
I'm doing a small add-on which is targeting an API that returns JSON
I'm trying to get this to work in a template.
If I dump the var out, I get the below response
{xen:helper dump, $usage}
and if I use the {xen:helper json, $usage} it returns:
How do I actually go about formatting this for use in a template now?
This is really easy in normal PHP as I just split the results in the foreach to separate variables
Thanks,
I'm trying to get this to work in a template.
If I dump the var out, I get the below response
{xen:helper dump, $usage}
Code:
object(stdClass)#99 (6) {
["24h"] => string(4) "2 GB"
["48h"] => string(4) "4 GB"
["30d"] => string(5) "14 GB"
["02m"] => string(7) "0 Bytes"
["01m"] => string(7) "0 Bytes"
["00m"] => string(5) "14 GB"
}
and if I use the {xen:helper json, $usage} it returns:
Code:
{"24h":"2 GB","48h":"4 GB","30d":"14 GB","02m":"0 Bytes","01m":"0 Bytes","00m":"14 GB"}
How do I actually go about formatting this for use in a template now?
This is really easy in normal PHP as I just split the results in the foreach to separate variables
PHP:
$usage = json_decode($resp);
echo "<table>";
foreach($usage as $k=>$v)
echo "<tr><td>$k</td><td>$v</td></tr>";
echo "</table>";
Thanks,