Hi!
I build a little REST Api like this https://getkirby.com/docs/cookbook/json
and Using the JSON content api in combination with multilanguage sites
But what i have to do (i need the specific fields from my code) to get the correct JSON output for each language?
Here is an example, it works fine without multi language. For the URL ‘http://localhost:8000/investments/api’ i get this output:
"items": {
"pageTitle": "Investments",
"headline": "We provide you access to highly curated, top quartile, private equity funds."
},
"investments": [
{
"title": "Investment Committee",
"text": "The final hurdle every investment opportunity has to cross is our Investment Committee of seasoned industry experts. The committee's decisions are based on the members' deep industry knowledge and past experience, which complement our data-driven due diligence process."
},
{
"title": "Sourcing",
"text": "We keep close ties with academics, stay on top of the latest research and maintain tight relationships with industry insiders to get preferred access to the exclusive and robust investment opportunities."
},
{
"title": "Due Diligence",
"text": "We have a standardized approval process before investment opportunities go on our platform. We are completely independent and only select an offering if we feel comfortable investing our own money."
}
]
}
My example code:
<?php
header('Content-type: application/json; charset=utf-8');
$dataJSON = new stdClass;
$staticDataArray = new stdClass;
$investmentArray = array();
$data = $pages->find('investments');
$childData = $pages->find('investments')->children()->visible()->flip();
$staticDataArray->pageTitle = (string)$data->title();
$staticDataArray->headline = (string)$data->text();
foreach($childData as $investmentChild) {
$investmentArray[] = array(
'title' => (string)$investmentChild->title(),
'text' => (string)$investmentChild->text()
);
}
$dataJSON->items = $staticDataArray;
$dataJSON->investments = $investmentArray;
echo json_encode($dataJSON);
?>
Does anyone know an idea to solve this?