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

Content not accessible in webc file (Error: "Tried to use templateContent too early") #92

Open
rothsandro opened this issue Dec 4, 2023 · 2 comments

Comments

@rothsandro
Copy link

The content of other pages is not accessible inside webc pages.

Repro

  1. Create a new Eleventy + WebC project
  2. Add some markdown files with "posts" tag
  3. Add a .webc page that renders a list of posts with the content
---
layout: base
---

<div webc:for="post of collections.posts">
  <div @raw="post.content"></div>
</div>

Repro: https://github.com/rothsandro/repro.eleventy-webc-content

Expected

The posts with their content should be rendered.

Actual

An error is thrown

Tried to use templateContent too early on ./src/blog/post1.md

Further information

This happens only with WebC. If I do the same on a njk page it works fine.

The repro project cannot be started at all, it always fails.
My actual project often starts properly (locally, but not on Netlify), the error just occurs every few times.

Versions

@11ty/eleventy: 2.0.1
@11ty/eleventy-plugin-webc: 0.11.1

Node v18.16.0
npm v9.5.1
@rothsandro rothsandro changed the title Content not accessible in webc file (Error: "Tried to use templateContent too") Content not accessible in webc file (Error: "Tried to use templateContent too early") Dec 4, 2023
@noelforte
Copy link

noelforte commented Feb 7, 2024

Having the same issue, although I can't get my build to start at all. Paging through some of the other issues in 11ty/eleventy it appears that there's some sort of dependency-race-condition occuring where the templates content hasn't been built yet but the call to .content/.templateContent runs before Eleventy can transform the content of the template in question.

It looks like eleventyImport.collections (related GH issue) exists to mitigate template render order issues but I haven't figured out how to get to apply to WebC yet. Hopefully either a fix or workaround will come soon!

@chmking
Copy link

chmking commented Feb 21, 2024

I recently hit the same issue and was putting together a minimum repro when I found this.

I have the same inconsistency where the minimum repro won't start at all. My other project will start fine but breaks the moment I edit anything triggering the reload.

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

No branches or pull requests

3 participants