getEntry()

getEntry() loads a single content collection entry by its id.

Since Astro 2.5 Spec ↗

Syntax

const post = await getEntry('blog', slug)

Returns

Promise<CollectionEntry | undefined> — A promise resolving to the matching entry, or undefined if not found.

Examples

---
import { getEntry } from 'astro:content';
const post = await getEntry('blog', Astro.params.slug);
if (!post) return Astro.rewrite('/404');
const { Content } = await post.render();
---
<h1>{post.data.title}</h1>
<Content />
Output
Loads one post by slug, 404s if missing, and renders its body.

Notes

Imported from astro:content. Also accepts a reference object form getEntry(ref). Call render() (or use the render() util) to get the Content component for Markdown/MDX bodies.

See also