4

What is the best way to get the url for each item added to a ContentList field?

Right now, I only get fields and id.

1 Answer 1

5

I assume you are running in "connected" or "integrated" mode, right? By default the MultilistFieldSerializer responsible for the multilist field serialization (what the ContentList ultimately becomes after app import) does not serialize url and I believe was done to make the serializer more efficient.

You have two options:

1) Use integrated GraphQL to reshape the datasource data that comes out of the component, see more about the feature here: https://jss.sitecore.net/docs/techniques/graphql/integrated-graphql#integrated-graphql-in-jss-apps

2) Extend the default MultilistFieldSerializer and add url to the list of serialized fields.

I'd explore the first option first, since it would not require any .NET coding or changes to the configuration.

BTW, I had filed a similar issue in GitHub as well: https://github.com/Sitecore/jss/issues/69

Hope this helps!

2
  • Thanks. Is there is way to extend "js version" of MultilistFieldSerializer, so url is populated automatically in the mock data? Nov 2, 2018 at 5:35
  • this should work if you add the url property on the item your content list field is referencing for disconnected development and the mocked layout service should return it. If you are using YAML for your route data, add url: /path/to-your-item in there next to id or name properties (not within the fields). This will work for you in the disconnected (mocked) environment, but it won't do anything for when the app is integrated so the url property would be lost unless your back-end dev extends the MultilistFieldSerializer. Pls DM me on Twitter if this doesn't make sense @alexshyba.
    – Alex Shyba
    Nov 4, 2018 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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