kreativan
1/27/2018 - 1:49 PM

Processwire Page2JSON

Processwire Page2JSON

<?php
 
$p = $pages->get($pageId);
 
// array for storing page data with added page id
$pdata = ["id" => $pageId];
 
// loop through the page fields and add their names and values to $pdata array
foreach($p->template->fieldgroup as $field) {
    if($field->type instanceof FieldtypeFieldsetOpen) continue;
    $value = $p->get($field->name); 
    $pdata[$field->name] = $field->type->sleepValue($p, $field, $value);
}
 
$response = $pdata;
 
// render the response and body
http_response_code($statuscode);
header($header);
echo json_encode($response);