Hi, new to Gatsby and JAMStack setup and still trying to get to grips with everything, so apologies if this is something apparent I've not understood via the docs.
I've managed to get posts created via Contentful, however, I'd like to add the ability to edit content on existing pages and if possible add new sections/content to those existing pages rather than create separate pages for those sections.
So, for example, say you have a one-page website and that has sections such as 'About us', 'What we do', 'Contact us' etc. What would be the best approach to making those sections individually editable via Contentful?
Editable in the Contentful UI?
@KyleAMathews Yeah, that's right. I wouldn't mind a solution that uses NetlifyCMS either, really just need something easy for clients to use.
@squaredindex I'm using Gatsby + Contentful + Netlify and loving it in terms of how flexible the entire setup is. An enjoyable developer experience and the clients love the simplicity of editing content via Contentful compared to other solutions I had wired up for Jekyll but really never felt truly stoked on.
I'd recommend a couple things to get into the groove quicker.
I'm very new to it myself but hopefully this helps.
Oh and be sure to join us all on the Spectrum community for Gatsby! Its pretty fun for open ended discussions on the fly.
I might be able to help here. I create a custom Content Model for each page that I want for the user to be able to edit.
Homepage

About page

You have to make sure that there is only 1 entry for each page’s Content Model. This is a little bit of a workaround, but it gets the job done. Notice the _Single entry protection_ field? Here are the settings for that field:



Key here being Required field, Unique field, and Accept only specified value — which I have set to ugs (you can change ugs to whatever, I choose it because it’s my client’s initial).
I then create an entry, the only valid entry for the entire Content Model. When user tries to create another entry, he/she won’t be able to publish it, because I have reserved the only valid protection keyword.

Now, querying with Gatsby is easy, you don’t even have to know the ID of the entry.
export const query = graphql`
query HomeQuery {
contentfulPageHome(protection: { eq: "ugs" }) {
metaDescription {
metaDescription
}
bannerImage {
description
resize(width: 1344) {
src
width
height
}
}
bannerCopy {
childMarkdownRemark {
html
}
}
...FeaturedBrandFragment
}
}
`
export const query = graphql`
query AboutQuery {
contentfulPageAbout(protection: { eq: "ugs" }) {
metaDescription {
metaDescription
}
introduction {
introduction
}
stats {
internal {
content
}
}
}
}
`
@ryanditjia Thank you so much for giving such a complete & clear explanation, that was incredibly helpful! 😁
This sort of setup will work perfectly for my client.
@grantly7 Thanks for sharing those resources, looking forward to really diving in and learning as much as possible.
No worries. It’s a workaround and can be bypassed by a naughty user deleting the entry and creating a new one from scratch. Just have to tell them not to do that 😃. Consider closing the issue if it’s solved your problem.