daizumi
September 13, 2016, 3:15pm
1
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}}'
texnixe
September 13, 2016, 3:51pm
2
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
philipp
September 14, 2016, 3:20pm
4
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
Maybe it helps!
daizumi
September 14, 2016, 3:37pm
5
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]
philipp
September 14, 2016, 4:44pm
6
What’s your templates code?
texnixe
September 14, 2016, 5:39pm
7
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.
philipp
September 14, 2016, 7:10pm
8
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 ?
daizumi
September 14, 2016, 9:51pm
9
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?
texnixe
September 14, 2016, 10:07pm
10
@danieljacoby Which version of Kirby are you using? In my test install, the array for page doesn’t work at all.
texnixe
September 15, 2016, 6:28am
12
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
daizumi
September 15, 2016, 11:17am
13
OK, I will not use it for now, but stay tuned for that implementation in a future version. Thanks!