Hey,
I have a problem quite similar to here:
Hi - thanks for any help on this.
I have a query set up in my blueprint file to retrieve a list of names (titles of entries) in a select field.
All works fine - the dropdown is populated with the list of titles.
Blueprint:
artist:
label: Artist
type: select
options: query
query: site.find(‘artists’).children.listed
However when I use the following code in the template…
Artist: <?= $page->artist() ?>
The displayed result is the following:
Artist: artists/mark-rothko
which is the full …
so I want to query the title of a different page like so:
`office:
label: Office
type: select
options: query
query: site.find('offices').children.listed
multiple: false`
and then using this in the template:
<?php $office = $note->office()->title()?>
As a result I get the path: offices/kassel instead of the title: Kassel
Although I tried all the possibilities in the mentioned post, I still get either an query-error in the panel or php error in the template.
This was the alternative blueprint from the other post:
`office:
label: Office
type: select
options: query
query:
fetch: site.find("offices").children.listed
text: "{{ arrayItem.title }}"
value: "{{ arrayItem.title }}"
multiple: false`
This was the alternative php code:
<?= page( $page->office() )->title() ?>
Both are not working…
Thank you ahead!
nielszs:
<?= page( $page->office() )->title() ?>
You have to convert into a page object before you can call the title:
<?php if ( $p = $page->office()->toPage() ) : ?>
<?php echo $p->title() ?>
<?php endif ?>
But for this to work, you need to store the id of the page instead of title.
Ok thanks a lot, after lot of trying I finally understood
for the future, here is the code:
` options: query
query:
fetch: site.find("offices").children.listed
text: "{{ page.title }}"
value: "{{ page.id }}"`
template:
<?php if ( $office = $note->office()->toPage() ) : ?> <?php $officetitle = $office->title() ?> <?php endif ?>
The problem with the blueprint was: I first used type: pages
but it has to be select
Dunno why
texnixe
September 1, 2020, 7:13am
5
I thought you had a reason to use the select field. The pages field is usually the first thing to chose when dealing with pages as options. What did not work for you?
nielszs
September 1, 2020, 9:53am
6
Then I get the error in the panel:
Error in “office” field
Invalid value for “query”
Its just possible if I query simple:
`office:
label: Office
type: pages
options: query
query: site.find("offices").children.listed`