Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to select and transform data from structures #8

Open
bnomei opened this issue Mar 31, 2020 · 8 comments
Open

how to select and transform data from structures #8

bnomei opened this issue Mar 31, 2020 · 8 comments
Labels
needs: information ❓ Requires more information to proceed

Comments

@bnomei
Copy link

bnomei commented Mar 31, 2020

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.

@ghost
Copy link

ghost commented Mar 31, 2020

{
    "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

@bnomei
Copy link
Author

bnomei commented Apr 2, 2020

thanks @kms-rscholz
i tried something similar but must have made an error somewhere.

@bnomei bnomei closed this as completed Apr 2, 2020
@bnomei
Copy link
Author

bnomei commented Apr 11, 2020

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"
      }
    }
  }
}

@bnomei bnomei reopened this Apr 11, 2020
@bnomei
Copy link
Author

bnomei commented Apr 11, 2020

"actions": {
      "query": "page.action.toStructure",
      "select": {
        "link": true,
        "title": true
      }
    }

does work. but it seems to me structureItem does not.

@bastianallgeier bastianallgeier added the needs: information ❓ Requires more information to proceed label Jul 15, 2020
@renestalder
Copy link

renestalder commented Nov 19, 2020

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"
  }
}

@maxfrischknecht
Copy link

maxfrischknecht commented Apr 30, 2021

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.

@marco-land
Copy link

marco-land commented Mar 9, 2022

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',
                },
              },
            },
          },
        },
      },
    }

@vin-ni
Copy link

vin-ni commented Mar 15, 2022

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: information ❓ Requires more information to proceed
Projects
None yet
Development

No branches or pull requests

6 participants