1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-23 05:16:03 +02:00

feat(site-plugin): add ability to return entries in JSON Format #186

by adding param ?format=json
This commit is contained in:
Awilum
2019-08-30 19:59:08 +03:00
parent a4790f840f
commit 221e75824d

View File

@@ -40,6 +40,9 @@ class SiteController extends Controller
// Get uri
$uri = $args['uri'];
// Is JSON Format
$is_json = ($query['format'] && $query['format'] == 'json') ? true : false;
// If uri is empty then it is main page else use entry uri
if ($uri === '/') {
$entry_uri = $this->registry->get('settings.entries.main');
@@ -81,6 +84,15 @@ class SiteController extends Controller
// Run event onSiteEntryAfterInitialized
$this->emitter->emit('onSiteEntryAfterInitialized');
// Return in JSON Format
if ($is_json) {
if ($is_entry_not_found) {
return $response->withJson($this->entry, 404);
}
return $response->withJson($this->entry);
}
// Set template path for current entry
$path = 'themes/' . $this->registry->get('settings.theme') . '/' . (empty($this->entry['template']) ? 'templates/default' : 'templates/' . $this->entry['template']) . '.html';