Jump to content

bits-please

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by bits-please

  1. BitPoet, thank you. I guess I misunderstood what output formatting actually did! DaveP, not really. This is the expected behaviour. The hook only acts on the rendering if the request is ajax or if the Accept header value is application/json. The above snippet acts on pages rendering during an ajax/json request that have $options['json'], so that the result is stored in a variable instead of rendered. That's why I don't encode the array. Hope that was clear. Thanks for the help.
  2. Hi, first of all big thanks to the community and to the developers for this great product. I have a module that adds a hook before page render to act as rest endpoints. I added the hook with: $this->addHookBefore('PageRender::renderPage', $this, 'endpoint'); Everything works fine except the returned json has the ouput unformatted. I'm creating the json array with: $page->setOutputFormatting(true); $json = array(); foreach ($page->fields as $field) { $json[$field->name] = $page->get($field->name); } $json['id'] = $page->id; $json['name'] = $page->name; $json['created_user'] = $page->createdUser->name; $parentEvent->return = $json; A page with a title "Title between quotes" will have its json title property as title: ""Title between quotes"" Am I missing something or is this the expected behaviour? I also tried searching for a Page method that returns the field formatted, but it seems only getUnformatted exists. Thank you in advance.
×
×
  • Create New...