Skip to content
Sign inJoin waitlist

Using a headless CMS — Fitbricks Next.js

Connecting a headless CMS works the same for every Next.js template sold on Framebrick, so this page lists only what is specific to Fitbricks.

The approach, rich text, images, keeping pages fresh, and step-by-step guides for Sanity, Payload, Strapi and Directus are in Use a headless CMS with a Next.js template.

Pages read them through src/lib/content.ts: getPrograms / getProgram, getProgramCategories / getProgramCategory, getCities / getCity, getClubs / getClub, getFacilities, getTrainers / getTrainer, getPosts / getPost, getLegalPages / getLegalPage, and getCardRefs (the category and city lookups of the cards). Mirror src/content/types.ts in the CMS:

Collection In the demo Fields
Program 20 slug, name, category (a ProgramCategory slug), level (easy / medium / hard), duration (minutes), instructor, subtitle, image, video (a YouTube URL), about, benefits, details (rich text), plans (a list of { name, description, price, includes: string[] })
ProgramCategory 5 slug, name, color (hex), icon (an SVG), description
City 10 slug, name
Club 30 slug, name, city (a City slug), location, image, gallery (four images), about (rich text: paragraphs), facilities (Facility slugs), programs (Program slugs), address, mapUrl, phone, phoneHref, email, emailHref, hours ({ weekdays, weekends })
Facility 14 slug, name, description, image
Trainer 12 slug, name, title (the role), summary, image, about (rich text: paragraphs), programs (Program slugs), email, emailHref, phone, phoneHref, socials (a list of { name: "facebook" | "instagram" | "x", label, href }, href may be null)
Post 16 slug, title, category (text: Fitness Tips, Nutrition & Wellness, Mindset & Motivation, Member Stories), date, excerpt, image, body (rich text)
LegalPage 2 slug, title, updated, description (the lead), metaDescription, body (rich text)

Every image is { src, alt }.

  • Relations. They are by slug, resolved in the pages and in src/lib/to-ui.ts: a program’s category gives its Class Type, its card’s colour and icon and its category page; a club’s city the city on its cards, its city page and “More in {city}”; a club’s facilities and programs, and a trainer’s programs, are lists shown in their order (a slug with no item is skipped). A missing category or city is shown as the slug itself, so a reference field that returns slugs is the simplest mapping. A post’s category is plain text; “Related Articles” matches it exactly.
  • Order. Posts are sorted newest first by date in getPosts(); every other list keeps the order the CMS returns, so give those collections a sort field. The order decides what the short lists show: Home’s six clubs, six programs and six posts, Contact’s six clubs, the trainers band’s three trainers, the footer’s five programs, the free trial’s ten programs, “Recent posts” (the first six other posts), “Other Programs” (the first six of the other categories), “Other Club Location” (the first six of the other cities), “Other Trainers” (the first six others).
  • Default. The category with the slug default is left out of the filters and the program sidebar and lends its colour to “All Class” (src/components/sections/programs/category-filter.ts). It still gets a page.
  • getProgram, getClub and the other single-item helpers filter the full list, so they keep working when the list functions fetch from the CMS. The sitemap reads the same functions.
  • The footer’s legal links come from getLegalPages; the menu, the footer’s other columns and the store badges are src/content/site.ts, not collections.

Program texts, club and trainer abouts, post bodies and legal texts are blocks, not HTML:

{ type: "heading", level: 3 | 4, text: "…" } // posts: 3 and 4; legal pages: 3 (rendered as h2, h3)
{ type: "paragraph", text: "…" } // **bold**, [text](href), \n for a line break
{ type: "list", ordered: boolean, items: ["…", "…"] } // each item is a line of text with the same marks

The demo’s posts use level-3 and level-4 headings, paragraphs and bulleted lists; the legal texts level-3 headings, paragraphs with bold runs and links, and bulleted lists; the programs paragraphs (about) and bulleted lists (benefits, details). Clubs and trainers show only the paragraphs of their about. There is no italic, and no tables, images or quotes inside the text. Convert your CMS’s rich text to these blocks in your mapping function, bold as **…** and links as text (how).

Every photo sits in a frame and is cropped to fill it, so a photo of other proportions works; upload images at least as large as the layout uses:

Image Size
A program’s image (the full-width cover, the cards, the share image) 1920 × 1280
A category’s icon a white line icon, SVG
A club’s image (the cover, the cards, the share image) 1200 × 800
A club’s gallery (four) 800 × 533
A facility’s image 400 × 267
A trainer’s image (portrait) 800 × 1200
A post’s image (the cards, the cover, the share image) 1200 × 800

Photos go through next/image, which needs the CMS’s host in images.remotePatterns of next.config.ts (Images). Every photo fills a frame of its own shape, so the components need no width or height from the CMS. The category icons (and the logos) are drawn with unoptimized, so an SVG from the CMS is shown as it is.