-
-
Notifications
You must be signed in to change notification settings - Fork 498
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
Provide access to the contents of the current inner page (inside an Eleventy layout) #3458
Comments
Note that this workaround does not work if I'm trying to use this in the front matter of a layout, failing with a "Tried to use templateContent too early" error. It makes sense that the collection information isn't available at this point, but the actual page contents are available right there in my template with the |
You’re not looking for I’m not sure we can allow access to rendered output from inside of the same template (e.g. |
No, I'm specifically looking for the processed content of the inner page.
It's not circular because I'm trying to access the content of a page during layout rendering. This information definitely exists—it's available within the layout body as the |
Ah, thank you for the clarification! |
Thinking about this more, the ideal would be to have |
Is your feature request related to a problem? Please describe.
I'm looking to add OpenGraph metadata to my page, specifically a description that's automatically generated from a snippet of the text on the current page.
Describe the solution you'd like
I'd like a way to get the rendered contents of the current template (without any layout around it) from the
page
object. Specifically, I'm looking to process this HTML using some JavaScript and produce a simplified, truncated description for use in a<meta>
tag.Describe alternatives you've considered
I can work around this by passing
collections
to a filter, since this actually does have full metadata for the current page, and just iterating through it until I hit the current page. This is the code I'm using right now:However, this is inelegant and inefficient, since it involves iterating across every page of my website to render each one. It does demonstrate that the data I'm looking for exists somewhere, though.
Additional context
#1206 seems to suggest that at some point,
page.content
did exist andcontained the rendered contents of a template. However, it doesn't seem to anymore, at least using
this.page
in a JS filter in Eleventy 3.0.0-beta.1.The text was updated successfully, but these errors were encountered: