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

Not possible to use renderContent filter in Nunjucks include or macro #3665

Open
greatislander opened this issue Feb 24, 2025 · 0 comments
Open

Comments

@greatislander
Copy link

greatislander commented Feb 24, 2025

Operating system

macOS Sequoia 15.3.1 (24D70)

Eleventy

3.0.0

Describe the bug

Upgrading an old (pre-2.x) Eleventy site to v3, I ran into what seems to be a bug with the renderContent filter. The context is that the site uses front matter data for repeating content on pages, such as page sections. So you might have something like this:

---
title: Home
sections:
  - title: About Us
    content: This is who we are.
  - title: Our Work
    content: This is what we do.
  - title: Contact Us
    content: This is how to reach us.
---

In the template, had been using the following Nunjucks templates to render these sections (with a custom universal filter, markdown, that rendered Markdown to HTML using markdown-it:

_includes/layouts/home.njk

{% for section in sections %}
  {% include 'partials/components/section.njk' %}
{% endfor %}

_includes/partials/components/section.njk

<section>
  <h2>{{ section.title }}</h2>
  {{ section.content | markdown | safe }}
</section>

My hope was that with v3 I could drop the custom filter and use renderContent('md') like this:

_includes/partials/components/section.njk

<section>
  <h2>{{ section.title }}</h2>
  {{ section.content | renderContent('md') | safe }}
</section>

However it doesn't appear to work— I now get a blank output for the entire include (no <section>, <h2> or rendered content). Nothing appears in the debug logs when running DEBUG=Eleventy* npx @11ty/eleventy that points me in the right direction to solve this either.

I tried another approach based on this article— using a macro— and that didn't work either.

Reproduction steps

  1. Clone https://github.com/greatislander/11ty-rendercontent-test.
  2. Run npm start
  3. Visit http://localhost:8080 and see the output.

Expected behavior

The renderContent filter should work when used in Nunjucks included templates and macros.

Reproduction URL

https://github.com/greatislander/11ty-rendercontent-test

Screenshots

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant