$data = json_decode($result,true);
if (!empty($data)) {
$array = $data['data'];
return $modx->getChunk($tplChunk, $array);
} else {
$modx->log(modX::LOG_LEVEL_ERROR, 'failed');
}
{
"success":1,
"error":[
],
"data":{
"weight":"0.00kg",
"items":[
{
"key":"3",
"name":"Test #1",
"points":0,
"product_id":"50",
"model":"TP1",
"option":[
],
"quantity":"1",
"reward":"yes"
},
{
"key":"4",
"name":"Test #5",
"points":0,
"product_id":"52",
"model":"TP5",
"option":[
],
"quantity":"1",
"reward":"yes"
}
],
"vouchers":[
],
"coupon_status":"1",
"coupon":"",
"voucher_status":"1",
"voucher":"",
"reward_status":false,
"reward":"",
"sums":[
{
"title":"Sum Total",
"text":"Value 2",
"value":"Value 3"
}
],
"total_count":1
}
}
This question has been answered by BobRay. See the first response.
<div class="item">
weight: [[+weight]]
key: [[+key]]
name: [[+name]]
etc.
</div>
$fields = array();
$output = '';
foreach($data['items'] as $item) {
foreach($item as $key => $value) {
$fields['weight'] = $data['weight'];
$fields[$key] = $value;
$output .= $modx->getChunk('myChunk', $fields);
}
}
return $output;$fields = array();
$output = '';
foreach($data['data']['items'] as $item) {
foreach($item as $key => $value) {
$fields[$key] = $value;
}
}
$output .= $modx->getChunk('myChunk', $fields);
return $output;[data]
foreach($data['items'] as $item) {
foreach($item as $key => $value) {
...
$output .= $modx->getChunk('myChunk', $fields);// stuff you want at the top here
<div class="outer>
[[+inner]] // where the list of items goes
</div>
// stuff you want at the bottom here.
$fields = array();
$output = '';
foreach($data['data']['items'] as $item) {
foreach($item as $key => $value) {
$fields[$key] = $value;
}
}
$output .= $modx->getChunk('myChunk', $fields);
return $output;<div class="container"> [[+total_count]] and [[+weight]] <ul> [[!innerSnippet &tpl=`myInnerTpl`]] </ul> </div>