Heya
I am sort of struggling with the JSON API for checkboxes: Checkboxes | Kirby CMS
Not sure if I either did not understand it correctly, or if the documentation is missing something
I am using this route to create a JSON:
(get all tags present on the site and then populate an array with the count of the usage of the tags)
[
'pattern' => 'my-api/tags.json',
'action' => function () {
$tags = [];
foreach (site()->index()->pluck('tags', ',', true) as $k => $tag) {
$tags['Tags'][] = [ 'value' => $tag, 'text' => $tag . ' (' . site()->index()->filterBy('tags', $tag)->count() . ')' ];
};
return json_encode($tags);
}
],
JSON:
{
"Tags": [
{
"value": "cats",
"text": "cat (21)"
},
{
"value": "dogs",
"text": "dogs (0)"
},
(...)
this JSON is read by this blueprint:
categories:
type: checkboxes
options: api
api:
url: "https://www.example.com/my-api/tags.json"
fetch: Tags
text: "{{ item.text }}"
value: "{{ item.value }}"
This works.
But afaik this should be easier.
These things don’t seem to work for me:
- using
url: "{{ site.url }}/my-api/tags.json"
the checkbox blueprint it empty.
if I use the full URL it works - instead of the “full” blueprint, trying to just use
api: https://www.example.com/my-api/tags.json
does not work either (this is from the docs under #06).
It seems that the displayed text is thevalue
, not thetext
item in the json.
The docs refer to the “manual option setting”, which I can’t seem to find in the docs?
Again, using{{ site.url }}
does not work, either.
(nb: I change the JSON to be “flat”; to not use “Tags
” as the first element)
What am I missing?!
Any help is much appreciated, as I seem to get nowhere for the last hours