I am trying to use the JSS service Layout API to get the items from a datasource specified in a control.

When I set a specific item as a datasource, I do get the item fields.

enter image description here

enter image description here

But when I use a query to get multiple items, I don't get any data from the service. Only the text of datasource query.

enter image description here

enter image description here

I need to get the datasource items in the json. I am missing something? Should I extend the layout service for this to work?

up vote 3 down vote accepted

You have two options:

  1. Use Integrated GraphQL to query the rendering data you need: https://jss.sitecore.net/docs/techniques/graphql/integrated-graphql

  2. Extend an existing Rendering Contents Resolver or implement a custom Rendering Contents Resolver in order to use a search query as a datasource. The out-of-the-box resolvers are:

    • Datasource Resolver - The default behavior, serializes the rendering's datasource item
    • Datasource Item Children Resolver - Serializes the children of the datasource item
    • Context Item Resolver - Serializes the context item instead of the datasource item
    • Context Item Children Resolver - Serializes the children of the context item
    • Folder Filter Resolver - Serializes the descendents of the datasource item, excluding folders

    You can find information about Rendering Contents Resolvers here, they are fairly straightforward to implement: https://jss.sitecore.net/docs/techniques/extending-layout-service/layoutservice-rendering-contents

  • I want to be able to change the datasource based on personalization rules. I know it's possible using the layout service. Is it possible with GraphQL? – François Hébert Aug 24 at 11:07
  • 1
    Integrated GraphQL is passed a $datasource variable that is the parent rendering's datasource - post personalization. So yes, you can use personalization with integrated GraphQL. Connected GraphQL can also be personalized, again using the same $datasource variable but from the client side based on the LS response. See the docs for more details. – Kam Figy Aug 24 at 20:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.