kql
kql copied to clipboard
how to select and transform data from structures
i tried field.toArray and field.toStructure combined with arrayItem and structureItem like in query language but that did not work. best i could find out was to use field.yaml or a custom pagemethod.
i would love to see support for arrayItem and structureItem in kql since that would be most consistent imho.
{
"query": "page('guides/print/business-materials').children",
"select": {
"url": true,
"title": true,
"id": true,
"slides": {
"query": "page.slides.toStructure",
"select": {
"image": {
"query": "structureItem.image.toFile",
"select": {
"url": true,
"srcset": "file.srcset([300, 800, 1024])"
}
},
"description" : "structureItem.description"
}
}
},
"pagination": {
"limit": 10
}
}
This works for me
thanks @kms-rscholz i tried something similar but must have made an error somewhere.
i can not get it to work.
fields:
action:
label: Aktionen
type: structure
fields:
link:
type: text
required: true
title:
type: text
required: true
{
"query": "page('somepage')",
"select": {
"thisworksbutnofieldmethods": "page.action.yaml",
"thisdoesnotwork": {
"query": "page.action.toStructure",
"select": {
"link": "structureItem.link",
"title": "structureItem.title.html"
}
}
}
}
"actions": {
"query": "page.action.toStructure",
"select": {
"link": true,
"title": true
}
}
does work. but it seems to me structureItem
does not.
I feel like structureItem
above might reference a field with that name and not a method. So if your fields are named differently, the example will not work out of the box.
If we consider toStructure from the field methods documentation to be the right method, this actually works (as you pointed out). As in the following example, I have a structure field called "items", so to correctly convert to an JSON structure, the items property looks like this:
{
"select": {
"title": true,
"id": true,
"slug": true,
"items": "page.items.toStructure"
}
}
I justed tested this an structureItem
is actually a method and not a field name.
This works for me:
// mediaStructure => name of the structure field
// mediaImage => name of the image/files field of mediaStructure
// structureItem => seems to be the reference for the query inside mediaStructure query
query: "page('projects/" + params.slug + "')",
select: {
title: true,
id: true,
mediaStructure: {
query: 'page.mediaStructure.toStructure',
select: {
mediaImage: {
query: 'structureItem.mediaImage.toFile'
}
}
}
}
Could we make this part of the documentation? That would be great! Happy to help out if needed.
I have a similar issue with values from a multiselect field…
const query = {
query: `site.children.filterBy('uid', 'projekte').first`,
language: this.$i18n.locale,
select: {
title: true,
uid: true,
projects: {
query: 'page.children.listed',
select: {
title: true,
uid: true,
uri: true,
year: true,
student: {
query: 'page.student.split',
select: {
// this will return null
autoid: {
query: 'arrayItem.value',
},
},
},
},
},
},
}
+1