contentful / contentful-metalsmith

A plugin for Metalsmith that pulls content from the Contentful API
87 stars 32 forks source link

include depth of relations #48

Closed p3sn closed 7 years ago

p3sn commented 7 years ago

Hi All,

I have set include to 10, but still I don't get all data. At a depth of 3, I only get the .sys data.

---
title: Test Title
contentful:
  content_type: defaultPage
  include: 10
  entry_filename_pattern: page/${ fields.slug }/index
  entry_template: page.html  
layout: page.html
---

Do you have any idea why I don't get all content of all objects?

Regards, Peter

Khaledgarbaya commented 7 years ago

@p3sn can you share a snippet of code where you access the fields. do you have something like {fields.referenceField.fields.fielName} ?

p3sn commented 7 years ago

Hi @Khaledgarbaya ,

First I use this each: {{#each data.fields.layoutOfPage}} within the each, I use a partial: {{> partialLayout}}

In the partial I can load values like:

            <h2>{{ this.fields.title }}</h2>
            <h3>{{ this.fields.subtitle }}</h3>

And also: {{#each this.fields.cards}} or {{#each this.fields.faq}}

Which are related (relationship) to a content type cards and faq. But the only value {{this}} has within the last each loop is:

"sys": {
type: Link
linkType: Entry
id: 5Dc6Gl2ICW6k08AQkU8cwY
}

I think this is normal behaviour, but I used to work with the angular version before and including up to 10 worked like a charm.

Now I'm trying to get the same result, but as a static website with metalsmith.

Thanks, Regards, Peter

Khaledgarbaya commented 7 years ago

Hi @p3sn, Is the data.fields.layoutOfPage and array of references ? or a dictionary ? can you try to access the first element of it without the each. like data.fields.layoutOfPage[0].fields.

p3sn commented 7 years ago

Hi @Khaledgarbaya ,

In contentful it's a reference within a reference. I can't access it without the each. I only get the sys object of those references. As mentioned in the documentation in here: https://www.contentful.com/developers/docs/concepts/links/#link-values-in-entries I assume this is related to my case: I only get link sys-data and not the actual content of the linked entry.

Regards, Peter

Khaledgarbaya commented 7 years ago

@p3sn the plugin is using the javascript SDK which is do the link resolution for you

p3sn commented 7 years ago

@Khaledgarbaya, I understand.

That's why I added include: 10. And I should get 10 levels deep back, right?

Regards, Peter

p3sn commented 7 years ago

Just to clarify: This works: {{ data.fields. layoutOfPage.[0].fields.title }}

One level more does not work: {{ data.fields. layoutOfPage.[0].fields.cards.[0].fields }} it results in null / nothing

But sys does work: {{ data.fields. layoutOfPage.[0].fields.cards.[0].sys }} it results in [object Object]

Regards, Peter

Khaledgarbaya commented 7 years ago

~hmm, that should work unless there is a pagination problem, for example some of the includes didn't make to the current page of the payload. I think the plugin should maybe expose some configuration on how to deal with pagination. By default the API is returning 100 record per page and it can be set to max 1000.~

p3sn commented 7 years ago

Hi @Khaledgarbaya,

In the angular version (which should work almost the same), I didn't hit the limit of 100. I don't have that many records. I also narrowed down the number of entries by using content_type: defaultPage.

So I'm almost sure the limit isn't causing this issue. I also changed limit to 1000 to double check. Can it me that include isn't an option, because it's not mentioned in here.

Khaledgarbaya commented 7 years ago

@p3sn this is weird and it could be a bug of the plugin, the include is actually supported here and picked here are you using the latest version ? because the link you sent me is actually from an old fork

p3sn commented 7 years ago

@Khaledgarbaya Ah damn, that was it! I started with downloading the metalsmith-contentful example on github. I updated contentful-metalsmith ^0.7.0 → ^0.9.0 and now it works like a charm.

Thanks a lot for your help!

Regards, Peter

stefanjudis commented 7 years ago

Sweet!

I started with downloading the metalsmith-contentful example on github

Can you point us to the location where you found this fork referenced? :)

Anyways cool it works now!

p3sn commented 7 years ago

It's the example mentioned on the homepage of contentful-metalsmith github. Here is the link: https://github.com/contentful-labs/contentful-metalsmith-example

Khaledgarbaya commented 7 years ago

@p3sn @stefanjudis the example is now up to date also