I am working on a Silverstripe project and I would like to have a simple way to present the content of a CMS generated Page (or subtype of Page) as JSON.
Ideally, I would like to append "/json" at the end of the route, or send a parameter via post (json=true) and obtain a response in JSON format.
I tried adding an action to my CustomPage_Controller class like this:
public static $allowed_actions = array('json');
public function json(SS_HTTPRequest $request) {
// ...
}
But I cannot figure out how to make that work:
- What URL/Route should I use?
- How do I get the content of the page?