From 16b73feacd96ec523f67e704c02e2dbe7102b508 Mon Sep 17 00:00:00 2001 From: martin3walker <35141192+martin3walker@users.noreply.github.com> Date: Fri, 3 Aug 2018 16:31:12 +0200 Subject: [PATCH] Add section on includeLevel to readme Include a section about how to return links more than one level deep. Useful because the content structure advocated for by Contentful makes heavy use of references. So, this seems like a problem many people could run into. --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index cb1ef4e..164302a 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,31 @@ new Contentful({ }) ``` +### Returning Linked Content Entries + +Contentful allows you to link content types with a field called references. This can create a chain of links. For example __Content Entry A__ could contain a reference to __Content Entry B__, and __Content Entry B__ could further reference __Content Entry C__. + +Spike's default settings return only the first level of links, meaning that returning __Content Entry A__ from above will also retun __Content Entry B__, but not __Content Entry C__. There is an option called includeLevel that can be included in your Contentful object, which will allow you to return more levels of links than the default 1. This is extremely helpful if your content model relies heavily on references. + +```js +new Contentful({ + addDataTo: locals, + accessToken: 'xxx', + spaceId: 'xxx', + includeLevel: 10, + contentTypes: [ + { + name: 'posts', + id: '633fTeiMaxxxxxxxxx', + filters: { + limit: 10, + order: 'sys.createdAt' + } + } + ] +}) +``` + ### Transforms Contentful returns a lot of associated data and, as a result, we give you the ability to pass your own custom `transform` option to each content type allowing you to transform the data however you like before it's sent to your views.