Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing: Rendering content to HTML for getCollection #7245

Open
MiloParigi opened this issue Mar 8, 2024 · 0 comments
Open

Missing: Rendering content to HTML for getCollection #7245

MiloParigi opened this issue Mar 8, 2024 · 0 comments
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages.

Comments

@MiloParigi
Copy link

📚 Subject area/topic

Content collection - Rendering content to html

📋 Suggested page

https://docs.astro.build/en/guides/content-collections/#rendering-content-to-html

📋 General description or bullet points (if proposing new content)

The current documentation show us how to generate the content when using the getEntry method for one entry only:

Screenshot 2024-03-08 at 10 52 13

In my current use case, I have a collection of entries that I want to be rendered on one page. After fiddling for a few hours, here is a similar example to the one provided for one entry. but for multiple entries:

---
import { getCollection } from 'astro:content';
const blogEntries = await getCollection('blog');
const renderedBlogEntries = await Promise.all(blogEntries.map(async (blogEntry) => {
    const { Content, headings } = await blogEntry.render();
    return { ...blogEntry, Content, headings };
}));
---
<div>
  {blogEntries.map(blogEntry => (
      <h1>{blogEntry.data.title}<h1>
      <blogEntry.Content />
    ))}
</div>

I'll make a StackBlitz example when I have the time but I wanted to share the solution first, so that anybody stuck on this problem can at least fix it if they find this issue.

🖥️ Reproduction of code samples in StackBlitz

No response

@MiloParigi MiloParigi added the add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages.
Projects
None yet
Development

No branches or pull requests

1 participant