Query nested blocks fields

Hey,

is it possible to query nested blocks fields within a (multiselect) field right in the blueprint? Here is a small example of three blocks fields which are nested. How to get all thirdlevelblockentry values into the multiselect field?

Thanks


fields:
    firstLevelBlocks:
        type: blocks
        fieldsets:
            secondLevelBlocks:
                type: blocks
                fieldsets:
                    thirdLevelBlocks:
                        type: block
                        fieldsets:
                            thirdlevelblockentry:
                                type: text


multiselectQuery:
    type: multiselect
    options: query
    query:
        fetch: site.find("page-with-nested-blocks").firstLevelBlocks...[how to continue this query (if possible)]
        text: "{{ block.thirdlevelblockentry }}"
        value: "{{ block.thirdlevelblockentry }}"

Here is a solution using Kirby Collections. But still would be interesting to see, if you can do the query totally within the blueprint, without the need of a collection.

Put this collection definition under site/collections/my-nested-blocks.php:

<?php
    return function ($site) {
        $collection = new \Kirby\Cms\Collection();
        $firstLevelBlocks = $site->find('page-with-nested-blocks')->firstLevelBlocks()->toBlocks();
        foreach ($firstLevelBlocks as $firstLevelBlock) {
            foreach ($firstLevelBlock->secondLevelBlocks()->toBlocks() as $secondLevelBlock) {
                 foreach ($secondLevelBlock->thirdLevelBlocks()->toBlocks() as $thirdLevelBlock) {
                     $collection->add($thirdLevelBlock);
                 }
            }
        }
        return $collection;
    };

In your blueprint use it like this:

multiselectQuery:
    type: multiselect
    options: query
    query:
        fetch: kirby.collection("my-nested-blocks")
        text: "{{ block.thirdlevelblockentry }}"
        value: "{{ block.thirdlevelblockentry }}"

No, you can’t use loops (or any other complicated logic) in query language.