You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To put them all together, I iterate using collections:
//- _includes/blog.pugextends./baseof.pug blockmain
main(style="color: red;")!= content
h2 Blog posts
each post in [...collections.post].reverse()
!=post.content
This page inherits from a parent template via pug's extends:
//- _includes/blog.pug
html
head
meta(charset="utf-8")
meta(name="viewport"content="width=device-width, initial-scale=1.0")
title=title
body
blockmain blockscripts
This problem is that this doesn't work!
The blog post content should be blue, not black. Indeed, it appears post.content contains just the rendered markdown content, not the stylized layout content. The good news is the docs do affirm this:
..each collection item will have the following data:
page: ...
data: all data for this piece of content (includes any data inherited from layouts)
rawInput: ...
content: the rendered content of this template. This does not include layout wrappers.
The issue is that none of the following works:
each post in [...collections.post].reverse()
!=post.content//- doesn't include layout wrapper !=post.templateContent//- doesn't include layout wrapper !=post.data.content//- v2 only -- also doesn't include layout wrapper
The only way I can actually get the content rendered using the prescribed layout is to somehow load the rendered html from page.outputPath variable. But the only way I know how to do this (in v2) is with a filter, i.e.:
each post in [...collections.post].reverse()
!=filters.readHTML(post.page.outputPath)
Where the filter comes from the solution given in this issue:
Doing this in v3 is an open problem. Using a filter feels like a hack, but I don't know how to do this otherwise, none of the 11ty variables seem to have the layout wrapped content!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to achieve very basic layout chaining with pugjs, but it's just not working!
Consider the following example (which is available in this test repo):
Suppose I want to make a blog page (via
blog.pug
), whose blog posts are tagged withpost
, e.g. something like:I want to wrap the blog content in some html/css given by the layout
partials/post.pug
, let's say to make the text blue:To put them all together, I iterate using collections:
This page inherits from a parent template via pug's
extends
:This problem is that this doesn't work!
The blog post content should be blue, not black. Indeed, it appears
post.content
contains just the rendered markdown content, not the stylized layout content. The good news is the docs do affirm this:The issue is that none of the following works:
The only way I can actually get the content rendered using the prescribed layout is to somehow load the rendered html from
page.outputPath
variable. But the only way I know how to do this (in v2) is with a filter, i.e.:Where the filter comes from the solution given in this issue:
Doing this in v3 is an open problem. Using a filter feels like a hack, but I don't know how to do this otherwise, none of the 11ty variables seem to have the layout wrapped content!
Any and all feedback would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions