Input query language in Panel, parse in template

Is it possible to write Kirby’s query language in a text input, then transform that query in a template?

For example, in a page in the panel, could I put this into a text input:

site.find("events").children.filterBy("kind", "vft")

and then access these page objects in a template?

If so, what is the best way to handle things on the template end?

This seems to work:


Returns an array like this:

    [0] => Array
            [text] => Across the ocean
            [value] => notes/across-the-ocean

    [1] => Array
            [text] => A night in the forest
            [value] => notes/a-night-in-the-forest

    [2] => Array
            [text] => In the jungle of Sumatra
            [value] => notes/in-the-jungle-of-sumatra

    [3] => Array
            [text] => Through the desert
            [value] => notes/through-the-desert

    [4] => Array
            [text] => Himalaya and back
            [value] => notes/himalaya-and-back

    [5] => Array
            [text] => Chasing waterfalls
            [value] => notes/chasing-waterfalls

    [6] => Array
            [text] => Exploring the universe
            [value] => notes/exploring-the-universe


Thank you!

I know I can loop through to create page objects using value here, but is there a more efficient way to access these results as pages?

I don’t really know if this is the best way to go about it, just found this looking for “query” in the source code.

But yes, provided your query returns pages:

$query = Kirby\Form\Options::query('site.find("notes").children');
$collection = new Pages(A::pluck($query, 'value'));
foreach ($collection as $item) {
  echo $item->title();

May I ask what’s your use case?

I am building a block for the Builder plugin which pulls pages from elsewhere on the site, based on a query, and displays them if the query returns something. I am just trying to make the filtering as flexible as possible.

If you can suggest another way to handle this, that would be great.

Not really, at least nothing as flexible. But seems rather error prone to me, at least your editors would need to know basic query syntax and especially what fields they could possibly query.

Thanks. I’ll keep thinking…