Querying pages in blueprints

Hello there.

I’m working on an old Kirby 2 website and it’s my first time working with v2. I need to restructure some contents. It’s pretty much simple, I’ve a category page with subpages for each category containing the title, an image and some description text.

Then there’s a blog page with subpages for each post. Now I want to assign every post to a category (or multiple, but that’s not possible I’ve read).

I’m used to query the pages like this:

category:
    label: Category
    type: select
    options: query
      query: site.find('projecttags').children
      default: null

But in Kirby 2 it does not work. I couldn’t really find anything useful in the old docs. Maybe someone can help me out.

Thanks in advance!

I found this syntax an old project:

      category:
        label: Category
        type: select
        options: query
        query:
          fetch: pages # or children or siblings

So syntax like the one in your example probably wasn’t possible.

Other than that, maybe check out the source code. This is so long ago.

Thanks for the quick reply.

I think this could be a problem because of the structure. I’ll give it a try. Thank You!

Well, such an old project should no longer run in production, but I guess I don’t need to tell you that.

I didn’t make the site and I wanted to update. Client does nont want to update. So, I’ve no choice :frowning:

Then they cannot have certain functionality, their choice.

But they don’t understand it. Now I have to look for a workaround to get this connected. Could do it statically but that’s not the route I wanna go down.

First, make sure you’re at least using the last version of Kirby 2.
That was Kirby 2.5.14

Then I guess it would be

category:
    label: Category
    type: select
    options: query
    query:
      page: projecttags
      fetch: children

If that doesn’t work, I remember having a plugin in Kirby 2 that let you specify a PHP function to fetch any kind of options for a select field. That might work for you, too.

You’d need a plugin for yourself to load the function:

site/plugins/myplugin/myplugin.php:

<?php

class MyPlugin {
    static function projectTags($field) {
        $result = array();

        $page = page('projecttags');

        foreach ($page->children() as $tag) {
            $result[$tag->uid()] = $tag->title();
        }

        return $result;
    }
}

then in the blueprint:

fields:
    category:
        label: Category
        type: controlledselect
        controller: MyPlugin::projectTags
1 Like