Retreiving multiple values from structure items using query langyage

Hi all - I’m having trouble reference data from a structured field via query language that I was hoping for some help with.

In my site blueprint I am defining a series of colours:

colours:
  label: colours
  type: structure
  fields:
    swatch:
      label: Colour code
      type: color
    colourName:
      label: Colour name
      type: text

And in my page blueprint I am able to query these structured items so that they can selected:

projectColour:
  label: Project Colour
  type: select
  width: 1/2
  options:
    type: query
    query: site.colours.toStructure
    text: "{{ item.colourName }}"
    value: "{{ item.swatch }}"

But doing this only records what I set as the value (so in this case ‘item.swatch’) in the page content file. I’m stumped at how to record both values (‘colourName’ as well as ‘swatch’) from the structured field as separate variables that I can display in the template.

Currently I can only use ‘<?=$page->projectColour() ?>’ to retrieve just the one value.

Thanks!

You can’t, unless you do one of the following:

  1. Store both swatch and colorname as value, separated by some character, for example:
value: "{{ item.swatch }}|{{ item.colourName }}"

The explode the field value by the separator into an array that you can then use to get both values.

  1. You find the item corresponding to the swatch value in your site structure field with findBy, then get the colorName from that item.

Apologies for the late reply; that’s helpful thanks, all solved!