Hello,
Inside a blueprint strture block, I’m populating my select fields like this :
category:
label: Category
type: select
options: query
query:
fetch: site.findPageOrDraft(‘taxonomies’).list1.toStructure
text: “{{ structureItem.name }}”
value: “{{ structureItem.id }}”
This works fine. But can’t find how to print in my frontend snippet the Text of the option.
I tried to use the long notation with value and text :
query:
fetch: site.findPageOrDraft(‘taxonomies’).list1.toStructure
- value: “{{ structureItem.id }}”
text: “{{ structureItem.name }}”
But no luck. My select options are blank.
I proobably miss something.
Thank you.
Scott
Could you please post your frontend code?
In the template page, first loop through blocks :
foreach($blocks as $block) {
snippet(‘blocks/therapist’,[‘data’ => $block]);
}
Inside snippet :
<?php echo $data->name();?> // Name of Therapist / OK
<?php echo $data->category();?> // Only get id / Can't see how to retrieve Text option
Thanks.
Well, you need to get the value from your structure field
$structureItem = $site->findPageOrDraft(‘taxonomies’)->list1->toStructure()->findBy('id', $data->category());
if ($structureItem) {
echo $structureItem->name();
}
Thank you for your efficiency !
As I will have many select to print in my snippet, I was just wondering I could place a function into site methods to retrieve name of items…
Thanks again.
Scott
Maybe better a custom field method?