Guide on what ButterCMS Reference fields are, and how to use them to link to other content items like related products, author profiles, and categories
References are a powerful field type added to Pages and Collections that allow you to create links (or references) among your content. References provide the ability to link to Items from a Collection or Pages from a Page Type from a Collection or Page.You will configure your reference fields to be either “one-to-one” or “one-to-many” references:
Ask yourself: “Will this content be managed independently and potentially used on multiple pages?” If yes, use a Reference to a Collection. If it’s page-specific content, use a Repeater.
// Get all articles in a specific categoryconst articles = await butter.page.list('article', { 'fields.category.slug': 'tutorials'});// Get articles by a specific authorconst authorArticles = await butter.page.list('article', { 'fields.author.slug': 'jane-smith'});
from butter_cms import ButterCMSclient = ButterCMS('your-api-key')# Fetch page with referencesresponse = client.pages.get('*', 'article-page')article = response['data']['fields']# Access one-to-one referenceauthor = article['author']print(f"Author: {author['name']}")# Access one-to-many referencefor category in article['categories']: print(f"Category: {category['name']} ({category['slug']})")# Filter by referencetutorials = client.pages.all('article', { 'fields.category.slug': 'tutorials'})
How to use Reference fields in the ButterCMS dashboard
For common use-cases and how to implement them in the ButterCMS dashboard, see the article below:
Working with references
How to implement common use cases, including categories (grouping/filtering), testimonials (reusable content), and related articles (linking related content).