Perry
January 28, 2019, 7:34pm
1
Hello,
https://getkirby.com/docs/cookbook/templating/generating-json
I try to recreate the cookbook example.
if I call https://website.com/programm.json can I then see the json? or do I have fetch it for example: with javascript ?
because I only see the error page
structur
home
about
programm -> events.txt
event1 -> event.txt
event2 -> event.txt
template
<?php
$data = $pages->find('programm')->children()->published()->flip();
$json = [];
foreach($data as $article) {
$json[] = [
'url' => (string)$article->url(),
'title' => (string)$article->title(),
'text' => (string)$article->text(),
'date' => (string)$article->date()
];
}
echo json_encode($json);
Just guessing; but shouldn’t you been using ->listed()
instead of ->published()
?
bnomei
January 28, 2019, 7:55pm
3
the template file of your is site/templates/events.json.php
?
does a site/templates/events.php
template exist?
does a blueprint site/blueprints/pages/events.yml
exist and is valid (page editable in panel)?
Perry
January 28, 2019, 8:27pm
4
@bnomei 3*yes
maybe there is an error in the file names
the name of the dir is “programm”
the textfiles “events” and “event”
the normal template-name is events.php
and for the json output events.json.php
what is the right url to see the json output
https://website.com/programm.json
or
https://website.com/events.json
?
bnomei
January 28, 2019, 8:42pm
5
should be this
https://website.com/programm.json
but make sure the regular template is working before setting up content representation…
https://website.com/programm
Perry
January 28, 2019, 8:46pm
6
yes is working.
<main class="width-100 flex justify-content-center align-item-center">
<?php foreach($page->children()->published() as $article): ?>
<div><?php echo $article->title() ?></div>
<?php endforeach ?>
</main>
bnomei
January 28, 2019, 9:03pm
7
try removing the logic in the content rep. maybe there is an issue there?
<?php echo json_encode(['test']);
Perry
January 28, 2019, 9:57pm
8
no still the error page.
my site is multi-language, can associate with it ?
texnixe
January 28, 2019, 10:06pm
9
Are you using the /
root for the default language? Then => bug
Describe the bug
When trying to access a content representation, for example, https://example.com/about.json in a multi-lingual setup, Kirby returns the error page.
To...
type: bug 🐛
1 Like
Perry
January 28, 2019, 10:10pm
10
oh yes!
<?php
return [
'code' => 'de',
'default' => true,
'direction' => 'ltr',
'locale' => 'de_DE',
'name' => 'Deutsch',
'url' => '/'
];
Perry
January 28, 2019, 10:33pm
11
now it works, thank you
https://site.com/de/programm.json
<?php
return [
'code' => 'de',
'default' => true,
'direction' => 'ltr',
'locale' => 'de_DE',
'name' => 'Deutsch',
'url' => '/de'
];