Contentful
Overview
Contentful is a headless CMS platform that you can use out-of-the-box with the Storefront Application. For more information on the features of Contentful itself, refer to the Contentful documentation.
Storefront Integration
The Contentful integration with the SCAYLE Storefront Application can be separated by concerns of local development (using contentful-cli
) and shop runtime (using Contentful Delivery API).
Initial Development Setup
The initial setup of Contentful within the SCAYLE Storefront Application requires the creation of a dedicated local .env.contentful
file. This file will contain all Contentful-relevant environment variables necessary to work with the Contentful Management API.
- Create a
CONTENTFUL_MANAGEMENT_TOKEN
: This token can be created as part of your Contentful account settings. - Source the
CONTENTFUL_SPACE_ID
: TheCONTENTFUL_SPACE_ID
can be found in General Settings once you are logged into Contentful. For more information on finding your Contentful space ID, see in the Contentful Guide.
Scripts
As part of the Storefront Application's package.json
, some additional scripts are included to interact with Contentful:
contentful:download
: Usescontentful-export
to download all data from the respective Contentful space. You can modify it as needed. Data will be stored incontentful.{SPACE_ID}.json
inside the root directory of your application.contentful:generate
: Running this command will generate all type definitions from yourcontentful.{SPACE_ID}.json
as well as some type guard functions, usingcf-content-types-generator
. The generated types will be located inside./modules/cms/providers/contentful/types/gen
.
Type Definitions
- Manual type definition:
./modules/cms/providers/contentful/types/contentful-defs.d
- Generated type definition:
./modules/cms/providers/contentful/types/gen/*
Shop Runtime Integration
The runtime integration between Contentful and the Storefront Application uses the Contentful Content Delivery API.
- Set CMS Provider: To use Contentful with the Storefront Application, set the CMS provider to
contentful
in yournuxt.config.ts
:
- Provide API Credentials: To access the Contentful Content Delivery API, you need to provide an
accessToken
andspaceID
as environment variables:
After adding environment variables to your .env
, your integration is complete.
- Runtime Configuration (Optional): You can also modify your
accessToken
andspace
inruntimeConfig
to override environment variables:
The integration additionally relies on the @nuxt/image
module (see the Nuxt Image module documentation) to handle images used with Contentful components.
Live Preview
The Preview Delivery API is used during the initial load to display unpublished changes in the Contentful editor. To accomplish this, an additional preview access token is required. Without it, unpublished changes will only be visible after they are published in the editor.
To enable the preview token in your runtime configuration:
When setting up the preview URLs within Contentful, also add the query param ?_editorMode={entry.sys.updatedAt}
to the URL. This action informs the site to bypass the cache and load Contentful's live preview SDK seamlessly.
.png)
Preview URL Setup
Deployment Requirements
Our implementation provides integration with the Nuxt RuntimeConfig functionality. This means that NUXT_PUBLIC_CMS_ACCESS_TOKEN
and NUXT_PUBLIC_CMS_SPACE
can be set during the application's runtime as environment variables instead of during build time, enhancing deployment flexibility.
Auto-Imported Components
Contentful components are auto-imported from the ~/modules/cms/providers/contentful/components
directory. To prevent component name collisions, we added the prefix CMS
to every component. For example, a component named Image
would be used as <CMSImage>
.
Ready Components
The following components are implemented as part of the Storefront Application, meaning they are available out-of-the-box for all shops that are built upon this foundation:
Accordion
AccordionEntry
Banner
BannerLink
ClickableImage
Image
Link
Text
Video
DetailImage
Grid
GridTile
ImageSlider
ImageSliderSlide
ImageText
Page
Product
ProductSlider
ScrollableLinkList
SlideShow
Story
ContentfulLink
The current implementation will add 'CMS'
prefix to every component so when you are using components inside of a template you should use:
Fetching Content
The Storefront Application provides simple ways to fetch content from Contentful.
useCMS()
Composables: As content from Contentful allows references to data provided by SCAYLE (e.g., product data), the Storefront Application features theuseCMS
composable. This composable internally relies on thecontentful
package to fetch content.
An example usage for getting relevant content might look as follows:
const {
data, status,
} = useCMSBySlug<TypeContentPageSkeleton>(
`content-page-${props.slug}`,
{
content_type: 'contentPage',
'fields.slug[match]': `content/${props.slug}`,
},
)
- The
useCMS
composable exposes the following data and functions as dedicated composables:useCMSBySlug
: Wraps around Nuxt'suseAsyncData
function using thecontentful
package to fetch Contentful content by slug (a user-friendly and URL-friendly string used to identify content).- The Contentful entry you are fetching must have a
slug
field and value that matches what you are trying to fetch.
- The Contentful entry you are fetching must have a
useCMSByFolder
: Wraps around Nuxt'suseAsyncData
function using thecontentful
package to fetch Contentful content by slug (a user-friendly and URL-friendly string used to identify content) for a folder.- The Contentful entry you are fetching must have a
slug
field and value that starts with the slug you want to fetch.
- The Contentful entry you are fetching must have a
defaultCMSOptions
: Returns default options for fetching, such aslocale
,env
, etc.
Basic Composables and Helpers
The Storefront Application includes a few simple reusable composables and helpers to simplify the usage of certain functionalities with Contentful components:
useCMSAligment()
: Provides Tailwind-compatible alignment classes for Contentful components.useContentfulImage()
: Provides utilities to process and return a sanitized teaser image object for Contentful components.useContentfulMargins()
: Provides Tailwind-compatible margin classes for Contentful components.useCMSListingContent()
: Returns a formatted object for usage with listings containing the CMS content,preListingContent
,postListingContent
, andhasTeaserImage
.
Components
This section offers a detailed overview of various shop areas utilizing Contentful content, alongside their options. It's essential to review the type definitions (./modules/cms/providers/contentful/types/gen/*
) for actual values and expected data types.
Homepage
Component: SlideShow
Parameter | Details |
---|---|
uid? | string |
h1? | string |
slides? | TypeSlideSkeleton |
marginTop? | TypeMarginSkeleton |
Component: Slide
Parameter | Details |
---|---|
uid? | string |
image? | TypeImageSkeleton | TypeVideoSkeleton |
topline? | string |
headline? | string |
ctaLabel? | string |
ctaUrl? | string |
isDark? | boolean |
align? | 'center' | 'end' | 'start' |
justify? | 'center' | 'end' | 'start' |
Component: ImageSlider
Parameter | Details |
---|---|
uid? | string |
headline? | string |
ctaLabel? | string |
ctaUrl? | string |
slides? | TypeImageSliderSlideSkeleton[] |
marginTop? | TypeMarginSkeleton |
Component: ImageSliderSlide
Parameter | Details |
---|---|
uid? | string |
image? | Asset |
topline? | string |
headline? | string |
isNew? | boolean |
ctaLabel? | string |
ctaUrl? | string |
tracking? | TypeTrackingSkeleton |
Component: Grid
Parameter | Details |
---|---|
uid? | string |
marginTop? | TypeMarginSkeleton |
isContainered? | boolean |
isContaineredDesktop? | boolean |
isSpaced? | boolean |
columns? | TypeClickableImageSkeleton | TypeCmsTextSkeleton | TypeGridTileSkeleton | TypeImageSkeleton | TypeImageTextSkeleton | TypeParagraphSkeleton | TypeProductSkeleton | TypeShopableImageSkeleton | TypeVideoSkeleton |
Component: GridTile
Parameter | Details |
---|---|
uid? | string |
content? | TypeClickableImageSkeleton | TypeImageSkeleton | TypeProductSkeleton | TypeShopableImageSkeleton | TypeVideoSkeleton |
headline? | string |
cta? | string |
ctaLink? | string |
Component: ImageText
Parameter | Details |
---|---|
uid? | string |
image? | TypeImageSkeleton[] |
topline? | string |
headline? | string |
text? | string |
cta? | string |
ctaLink? | string |
align? | 'center' | 'end' | 'start' |
justify? | 'center' | 'end' | 'start' |
Component: ProductSlider
Parameter | Details |
---|---|
uid? | string |
headline? | string |
ctaLabel? | string |
ctaUrl? | string |
productIds? |
References to SCAYLE products |
marginTop? | TypeMarginSkeleton |
Component: Banner
Parameter | Details |
---|---|
uid? | string |
isActive? | boolean |
type | 'hightlight' | 'info' | 'sale' |
body? | string |
countdownUntil? | string |
links? | TypeBannerLinkSkeleton[] |
ctaUrl? | string |
Component: Entry
Parameter | Details |
---|---|
color | string |
image | Asset |
label | string |
ctaUrl | string |
Footer
Component: Footer
Parameter | Details |
---|---|
uid? | string |
slug | string |
text? | Richtext |
alignRight? | boolean |
linkGroups? | TypeLinkGroupSkeleton[] |
textBottom? | string |
socialMedia? | TypeSocialMediaLinkSkeleton[] |
Component: LinkGroup
Parameter | Details |
---|---|
uid? | string |
title? | string |
links? | TypeLinkSkeleton[] |
Component: Link
Parameter | Details |
---|---|
uid? | string |
label | string |
ctaUrl | string |
openInNewTab? | boolean |
Listing Pages
Component: ListingPage
Parameter | Details |
---|---|
uid? | string |
teaserImage? | Asset |
teaserImageMobile? | Asset |
preListingContent? | EntrySkeletonType[] |
postListingContent? | EntrySkeletonType[] |
seo? | TypeSeoSkeleton |
Service Pages
Component: Accordion
Parameter | Details |
---|---|
uid? | string |
hasLinkList? | boolean |
entries? | TypeAccordionEntrySkeleton[] |
marginTop? | TypeMarginSkeleton |
Component: AccordionEntry
Parameter | Details |
---|---|
uid? | string |
title? | string |
linkTitle | string |
body? | Richtext |
Content Pages
Component: Content Page
Parameter | Details |
---|---|
uid? | string |
teaserImage? | Asset |
teaserImageMobile? | Asset |
headline? | string |
subline? | string |
content? | Array<TypeAccordionSkeleton
|
| | seo?
| TypeSeoSkeleton
|
All Pages
Component: Video
Parameter | Details |
---|---|
uid? | string |
control_color? | string |
autoplay? | boolean |
has_controls? | boolean |
is_containered? | boolean |
video | Asset |
preview_desktop_image? | Asset |
preview_mobile_image? | Asset |
loop? | boolean |
tracking? | TypeTrackingSkeleton |
marginTop? | TypeMarginSkeleton |
Component: ClickableImage
Parameter | Details |
---|---|
uid? | string |
image? | TypeImageSkeleton[] |
ctaUrl? | string |
tracking? | TypeTrackingSkeleton |
marginTop? | TypeMarginSkeleton |
Component: Image
Parameter | Details |
---|---|
uid? | string |
desktopImage? | Asset |
mobileImage? | Asset |
tracking? | TypeTrackingSkeleton |
Component: Text
Parameter | Details |
---|---|
uid? | string |
body? | Richtext |
Component: DoubleColumn
Parameter | Details |
---|---|
uid? | string |
columnRight? | EntrySkeletonType[] |
columnLeft? | EntrySkeletonType[] |
marginTop? | TypeMarginSkeleton |
Component: Paragraph
Parameter | Details |
---|---|
uid? | string |
headline? | string |
cta? | string |
body? | Richtext |
subTitle? | string |
image? | Asset[] |
Component: settings - tracking
Parameter | Details |
---|---|
item_id? | string |
item_name? | string |
promotion_id? | string |
promotion_name? | string |
creative_name? | string |
creative_slot? | string |
location_id? | string |
index? | string |
Component: settings - margin
Parameter | Details |
---|---|
marginTop | '2xl' | 'lg' | 'md' | 'sm' | 'xl' | 'xs' |
Component: settings - seo
Parameter | Details |
---|---|
title | string |
description | string |
ogTitle | string |
ogDescription | string |
ogImage | string |
twitterTitle | string |
twitterDescription | string |
twitterImage | string |