VisibleGrandchildren for dynamic options in blueprint

How do I fetch all visible grandchildren in a dynamic field, like e.g. a select? There’s grandchildren and visibleChildren, is it possible to combine both options somehow?

This is my code:

highlight:
  label: Highlighted Entry
  type: select
  options: query
  query:
    page: /
    fetch: grandchildren
    value: '{{uri}}'
    text: '{{title}}'

Unfortunately not. You have two to three alternatives, though:

  • use a custom field
  • use the query API
  • (modify the panel code)
1 Like

I have added your suggestion to a GitHub issue for 2.5.

1 Like

i wanted to do something similar recently.

What i ended up doing was using multiple templates like this:

  highlight:
    label: highlight
    type: select
    options: query
    translate: false
    query:
      fetch: grandchildren
      template: ['component', 'crossapp', 'channel']
      value: '{{uri}}'
      text: '{{title}}'

it doesn’t look for visible / invisible, but at least you can limit yourself to some folders of the same level :slight_smile:
Maybe it helps!

Good idea, @philipp!

I did my query like this:

query:
  page: ['who', 'program']
  fetch: visibleChildren
  value: '{{uri}}'
  text: '{{title}}'

It throws this error:
Warning: strpos() expects parameter 1 to be string, array given in /public_html/.../kirby/toolkit/lib/str.php on line 645

But it works!

[Edit removed]

What’s your templates code?

I’m surprised this works in the panel. From the source code, I’d say you can only pass a single page, not an array of pages, to the page attribute.

wait, did i implement this in the front end or did i only check if this works from the backend? wait a second

edit:

MY Blueprint

featured:
    label: Featured
    type: checkboxes 
    options: query
    translate: false
    query:
      fetch: grandchildren
      template: ['component', 'crossapp', 'channel']
      value: '{{uri}}'
      text: '{{title}}'

MY products.txt and selection of pages in content folder:

Featured: produkte/channel/invoice-channel, produkte/components/form-designer, produkte/components/kreditorenmanagement, produkte/components/capture-component, produkte/components/sharepoint-connector, produkte/crossapps/sd-connector

Your code to display the page titles could look like this:

<?php $highlights = $page->highlight()->split();
   foreach ($highlights as $highlight) {
     echo page($highlight)->title();
  } ?>

It should work ?

I checked my frontend again and it DOES work, without even errors there. (The error I had was due to something else.)

The panel still shows the error I mentioned above, and behaves strangely slow when saving but ultimately saves it. I’m tempted to keep it like this… is it bad?

@danieljacoby Which version of Kirby are you using? In my test install, the array for page doesn’t work at all.

I’m using version 2.3.1

Yeah, ok, it “works” in 2.3.1 and 2.3.2, not in the 2.4 developer version though. But I have no idea why, because the page method in fieldoptions.php expects a string, not an array, hence the php warning. Your workaround is likely to break unless a future version of kirby allows arrays.

I have created a feature request on GitHub.

1 Like

OK, I will not use it for now, but stay tuned for that implementation in a future version. Thanks!