I’m looking to use Kirby’s collection feature. I’m retrieving data from Kirby using Vue + the Content Rep API. I’m fine when fetching page-specific json using Axios but I’m unsure how to the same for collections, is this possible?
Below is what I have so far in kirby/site/collections/latest.php
<?php
return function ($site) {
return $site->find('shows')->children();
};
I would assume that retrieving the $site variable would give me what I need. But I only get the Title, children ( pages ), and routes in the response.
No, there are no content representations for collections. A Content Representation is a non-html representation of an HTML template, so xxx.json.php returns JSON etc. You will have to return the collection from the JSON template to be able to consume it from your Vue frontend.
Some variables, like $kirby, $site, $page and $page are globally available in controllers and templates/snippets. In collections, you can pass the $site and $usersvariables as argument to have them available within the anonymous function, I think.
In plugins, hooks etc. you would have to use the helpers kirby(), pages(), page() etc. to access those objects.