Querying page structure field value by structure index set in a subpage

On my parent page blueprint I have a structure field for defining a categories list.

On the children pages, there is a dropdown with options populated by this structure field. I can get the structure index and the category name value with a query

query: 
  fetch: site.children.find("parentpage").categories.toStructure
  text: "{{ structureItem.cat_name.value }}"
  value: "{{ structureItem }}"

On the parent page, in my list of subpages I want to list the category of each page in the info property

However info: "{{ page.category }}" returns me the index in the structure field, since that’s the value saved to the subpage. How can I translate this id to an actual value within the structure?

I’ve tried

info: "{{ page.category.cat_name }}"

and

info: "{{ page.category.cat_name.value }}"

with no luck either

Edit: Figured it out, here’s my query

{{ site.children.find("parentpage").categories.toStructure.find( page.category ).cat_name.value }}

This results in the index of 0 saved on the child page displaying Category 1 Name on the parent page in the pages list for the info property

The question is why you store the structureItem (and hence the index) instead of the cat name, because the index might actually change when the order of the items is changed.

1 Like

A valid point! I suppose I should include an id field or such in my structure rather than use the index itself

I didn’t store the category name itself for a similar reason, in case it was changed later

Yes, that would be the best. If you use the AutoID plugin, such an ID can be added automatically.