Skip to content
Sign inJoin waitlist

Using a headless CMS — Balancee 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 Balancee.

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: getServices / getService / getOtherServices, getPortfolio / getPortfolioItem / getOtherPortfolio, getPosts / getPost / getRelatedPosts and getLegalPages / getLegalPage. Mirror src/content/types.ts in the CMS:

Collection In the demo Fields
Service (services.ts) 8 slug, name, summary, image, intro, whatWeDo (title, text, image), offered (title, items: six of title and text), process (title, text, image, steps: four of title and text)
PortfolioItem (portfolio.ts) 8 slug, name, headline, summary, image, client, budget, duration, team, and four sections overview, challenges, solutions, results, each with title, body (rich text) and images; results also has stats (three of value and label)
Post (posts.ts) 9 slug, title, excerpt, image, category (text), date, author (name, role, avatar), body (rich text)
LegalPage (legal.ts) 2 slug, title, updated (a date), body (rich text)

An image is an object, { src, alt }: the path or address and its description. Dates are ISO dates ("2025-08-10"). The timeline, the awards and the team of About, the testimonials, the client logos and the process steps of Home and the Services page are page copy in src/content/pages/, not collections.

  • Related items. “Other blogs” under a post are the other posts with the same category, up to two (otherCount in src/content/pages/blog.ts), in list order (getRelatedPosts). category is plain text, matched exactly: a CMS option list or a reference to a category, mapped to its name, both work. The block is left out when no other post shares the category. “Other services” are the next three services and “Other case studies” the next two, in list order, never the item itself.
  • Order. Lists keep the order they arrive in; nothing is sorted by date. Posts are newest first in the demo (Blog, Home, related posts), so sort by date descending in your query. Home shows the first six services (services.count in src/content/pages/home.ts) and the first three posts (blog.count); Blog and Portfolio load four at a time (list.pageSize in blog.ts and portfolio.ts); the Services page shows every service; the footer lists the first five case studies and the first four services (caseStudyCount and serviceCount in site.ts).
  • Home picks case studies by slug. caseStudies in home.ts names six case studies (cards, spotlight, recent) by slug. That is a relation of Home’s copy to the collection: keep those slugs in the CMS, or change them in home.ts (a slug that no longer exists stops the build). Home’s accordion rows also show the first entry of the case study’s results.stats, so a case study needs at least one.
  • Services in the form. The contact form’s “I’m interested in …” choices are written out in contactForm (src/content/pages/shared.ts), not read from the collection: add a new service’s name there, or build the list from getServices() in the section.
  • Every item has a page. /service/<slug>, /portfolio/<slug>, /blog/<slug> and /legal/<slug> are built from the collections, and the sitemap reads the same functions. The footer’s legal links are written in footer.legalLinks (src/content/site.ts), not read from the collection.
  • A case study’s sections may have no photos (Merge Mastery’s overview and challenges): leave images empty.

A post’s body, a legal page’s body and every section body of a case study are blocks, not HTML:

{ type: "heading", level: 3, text: "…" } // drawn as one heading style, whatever the level
{ type: "paragraph", text: "…" } // **bold** between double asterisks, *italic* between single ones, "\n" for a line break
{ type: "list", ordered: false, items: [[{ type: "paragraph", text: "…" }], …] } // each item is its own list of blocks

The demo’s texts use headings, paragraphs and bulleted lists; numbered lists (ordered: true), bold and italics work too. There are no links or images inside the text. Convert your CMS’s rich text to these blocks in your mapping function, bold as **…** and italics as *…* (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 post’s image (360 : 236 on cards, 2.4 : 1 on its page, up to 1140 px wide) 2000 × 1333
A post’s author.avatar (48 px, round) 120 × 120
A service’s image (square on cards, 4 : 5 beside the intro, up to 517 px wide) 1034 × 690 or larger
A service’s whatWeDo.image (545 : 400) and process.image (up to 467 px wide) 1090 × 727 and 934 × 668 or larger
A case study’s image (560 : 475 on cards) 2400 × 1600
A case study’s section photos (a wide one of 12 : 5, the others 3 : 2, up to 950 px wide) 1900 × 1267; the small overview photos 620 × 413; the challenges 940 × 627

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 layout needs no width and height from the CMS.