Hi,
how can I create a select field with children of another page?
fields:
category:
label: Category
type: select
options: ???
Hi,
how can I create a select field with children of another page?
fields:
category:
label: Category
type: select
options: ???
You can use the query option:
options: query
query:
page: blog
fetch: children # or visibleChildren, depending on use case
value: '{{uri}}'
text: '{{title}}'
Alright, i used the following:
kuenstler:
label: Kuenstler
type: select
options: query
query:
page: kuenstler
fetch: children
value: '{{uri}}'
text: '{{title}}'
But the dropdown remains empty.
My content is structured like this:
That’s because your kuenstler
page is a subpage of bibliothek
. You have to pass the path:
page: bibliothek/kuenstler
From where are you querying?
The try a relative path like this:
page: ../../kuenstler
well, I reloaded everything, but it’s still empty
Well, the path I posted above should be correct, but maybe your indentation isn’t. Please check again. It should look like this:
fields:
kuenstler:
label: Kuenstler
type: select
options: query
query:
page: ../../kuenstler
fetch: children
value: '{{uri}}'
text: '{{title}}'
aaah, there it is! Thanks, @texnixe !
alright, one last thing here: i wnt to link from the generated field to the page i selected from.
i tried this:
<a href="<?= $page->kuenstler()->uri() ?>"><?= $page->kuenstler()->title()?></a>
but it leads to
mypage/bibliothek/bilder/bibliothek/kuenstler/william-talbot
where it should be
mypage/bibliothek/kuenstler/william-talbot
so there are two directories twice. How can i fix this?
You have to get the page object:
<a href="<?= ($p = $page->kuenstler()->toPage())? $p->url(): '' ?>"><?= ($p = $page->kuenstler()->toPage())? $p->title(): '' ?></a>
Or use an if statement around the complete link.
so far it works fine, thanks a lot!