Generating json

I try to recreate the cookbook example.

if I call can I then see the json? or do I have fetch it for example: with javascript ?
because I only see the error page


  • home
  • about
  • programm -> events.txt
    • event1 -> event.txt
    • event2 -> event.txt



$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()?

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)?

@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

should be this

but make sure the regular template is working before setting up content representation…

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 ?>


try removing the logic in the content rep. maybe there is an issue there?

<?php echo json_encode(['test']);

no still the error page.
my site is multi-language, can associate with it ?

Are you using the / root for the default language? Then => bug

1 Like

oh yes!


return [
  'code' => 'de',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'de_DE',
  'name' => 'Deutsch',
  'url' => '/'

now it works, thank you :smiley:


    return [
      'code' => 'de',
      'default' => true,
      'direction' => 'ltr',
      'locale' => 'de_DE',
      'name' => 'Deutsch',
      'url' => '/de'