docs
  1. Integrations
  2. Cms
  3. Contentful

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: The CONTENTFUL_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: Uses contentful-export to download all data from the respective Contentful space. You can modify it as needed. Data will be stored in contentful.{SPACE_ID}.json inside the root directory of your application.
  • contentful:generate: Running this command will generate all type definitions from your contentful.{SPACE_ID}.json as well as some type guard functions, using cf-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.

  1. Set CMS Provider: To use Contentful with the Storefront Application, set the CMS provider to contentful in your nuxt.config.ts:
  1. Provide API Credentials: To access the Contentful Content Delivery API, you need to provide an accessToken and spaceID as environment variables:

After adding environment variables to your .env, your integration is complete.

  1. Runtime Configuration (Optional): You can also modify your accessToken and space in runtimeConfig 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.

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 the useCMS composable. This composable internally relies on the contentful package to fetch content.
    An example usage for getting relevant content might look as follows:
  • The useCMS composable exposes the following data and functions as dedicated composables:
    • useCMSBySlug: Wraps around Nuxt's useAsyncData function using the contentful 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.
    • useCMSByFolder: Wraps around Nuxt's useAsyncData function using the contentful 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.
    • defaultCMSOptions: Returns default options for fetching, such as locale, 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, and hasTeaserImage.

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

ParameterDetails
uid?string
h1?string
slides?TypeSlideSkeleton
marginTop?TypeMarginSkeleton

Component: Slide

ParameterDetails
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

ParameterDetails
uid?string
headline?string
ctaLabel?string
ctaUrl?string
slides?TypeImageSliderSlideSkeleton[]
marginTop?TypeMarginSkeleton

Component: ImageSliderSlide

ParameterDetails
uid?string
image?Asset
topline?string
headline?string
isNew?boolean
ctaLabel?string
ctaUrl?string
tracking?TypeTrackingSkeleton

Component: Grid

ParameterDetails
uid?string
marginTop?TypeMarginSkeleton
isContainered?boolean
isContaineredDesktop?boolean
isSpaced?boolean
columns?TypeClickableImageSkeleton | TypeCmsTextSkeleton | TypeGridTileSkeleton | TypeImageSkeleton | TypeImageTextSkeleton | TypeParagraphSkeleton | TypeProductSkeleton | TypeShopableImageSkeleton | TypeVideoSkeleton

Component: GridTile

ParameterDetails
uid?string
content?TypeClickableImageSkeleton | TypeImageSkeleton | TypeProductSkeleton | TypeShopableImageSkeleton | TypeVideoSkeleton
headline?string
cta?string
ctaLink?string


Component: ImageText

ParameterDetails
uid?string
image?TypeImageSkeleton[]
topline?string
headline?string
text?string
cta?string
ctaLink?string
align?'center' | 'end' | 'start'
justify?'center' | 'end' | 'start'

Component: ProductSlider

ParameterDetails
uid?string
headline?string
ctaLabel?string
ctaUrl?string
productIds?

string

References to SCAYLE products

marginTop?TypeMarginSkeleton

Component: Banner

ParameterDetails
uid?string
isActive?boolean
type'hightlight' | 'info' | 'sale'
body?string
countdownUntil?string
links?TypeBannerLinkSkeleton[]
ctaUrl?string

Component: Entry

ParameterDetails
colorstring
imageAsset
labelstring
ctaUrlstring

Component: Footer

ParameterDetails
uid?string
slugstring
text?Richtext
alignRight?boolean
linkGroups?TypeLinkGroupSkeleton[]
textBottom?string
socialMedia?TypeSocialMediaLinkSkeleton[]

Component: LinkGroup

ParameterDetails
uid?string
title?string
links?TypeLinkSkeleton[]

Component: Link

ParameterDetails
uid?string
labelstring
ctaUrlstring
openInNewTab?boolean

Listing Pages

Component: ListingPage

ParameterDetails
uid?string
teaserImage?Asset
teaserImageMobile?Asset
preListingContent?EntrySkeletonType[]
postListingContent?EntrySkeletonType[]
seo?TypeSeoSkeleton

Service Pages

Component: Accordion

ParameterDetails
uid?string
hasLinkList?boolean
entries?TypeAccordionEntrySkeleton[]
marginTop?TypeMarginSkeleton

Component: AccordionEntry

ParameterDetails
uid?string
title?string
linkTitlestring
body?Richtext

Content Pages

Component: Content Page

ParameterDetails
uid?string
teaserImage?Asset
teaserImageMobile?Asset
headline?string
subline?string
content?

| | seo? | TypeSeoSkeleton |

All Pages

Component: Video

ParameterDetails
uid?string
control_color?string
autoplay?boolean
has_controls?boolean
is_containered?boolean
videoAsset
preview_desktop_image?Asset
preview_mobile_image?Asset
loop?boolean
tracking?TypeTrackingSkeleton
marginTop?TypeMarginSkeleton

Component: ClickableImage

ParameterDetails
uid?string
image?TypeImageSkeleton[]
ctaUrl?string
tracking?TypeTrackingSkeleton
marginTop?TypeMarginSkeleton

Component: Image

ParameterDetails
uid?string
desktopImage?Asset
mobileImage?Asset
tracking?TypeTrackingSkeleton

Component: Text

ParameterDetails
uid?string
body?Richtext

Component: DoubleColumn

ParameterDetails
uid?string
columnRight?EntrySkeletonType[]
columnLeft?EntrySkeletonType[]
marginTop?TypeMarginSkeleton

Component: Paragraph

ParameterDetails
uid?string
headline?string
cta?string
body?Richtext
subTitle?string
image?Asset[]

Component: settings - tracking

ParameterDetails
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

ParameterDetails
marginTop'2xl' | 'lg' | 'md' | 'sm' | 'xl' | 'xs'

Component: settings - seo

ParameterDetails
titlestring
descriptionstring
ogTitlestring
ogDescriptionstring
ogImagestring
twitterTitlestring
twitterDescriptionstring
twitterImagestring