#`render()` function of a content collection entry

3 messages · Page 1 of 1 (latest)

formal breach
#

In the render() function of a content collection entry, how can I obtain the HTML string instead of the Content Astro component?

Because I want to manipulate the HTML string before processing it into a <Fragment set:html>.

short glenBOT
#

Hi @formal breach. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The render() function of a content collection entry in Astro does not directly provide the HTML string. Instead, it returns a <Content /> component and other properties like headings and remarkPluginFrontmatter. The <Content /> component is used to render the document’s contents in an Astro file.

---import { getEntryBySlug } from 'astro:content';
const entry = await getEntryBySlug('blog', 'entry-1');
const { Content, headings, remarkPluginFrontmatter } = await entry.render();---

(Source: Astro API Reference (https://docs.astro.build/en/reference/api-reference/#render))

However, if you want to manipulate the HTML string before processing it into a <Fragment set:html>, you might need to convert the <Content /> component to a string. Unfortunately, the provided knowledge sources do not provide information on how to convert an Astro component to a string.

For more information on how to use the render() function and the <Content /> component, you can refer to the Astro Documentation (https://docs.astro.build/en/guides/content-collections/#rendering-content-to-html).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: