-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Possible to get page content in frontmatter? #329
Comments
Just saw #135, so I don't think what I mentioned above is possible :( Curious if you have any solutions though! |
Have a look at #179 (very similar tasks, i.e. excerpt creation). It sounds like you’re looking for shortcodes: https://www.11ty.io/docs/shortcodes/. You loop through your articles like you used to and then you can do something along the lines of: {% if post.description %}
{% excerpt post %}
{% endif %} |
@kleinfreund Unfortunately what I need is different from what you suggest. I need this for the |
Then you can try to implement the logic in the template that defines the |
Does this mean I should get I don't mind doing this. It feels a little hacky to parse through the frontmatter to get the content manually. |
Oh, right, I understand. I believed/had hoped that the Hm, in my opinion, Eleventy should have a more precise and consistent document model. When processing a file, I should have access to its front matter if present. I get that for documents inside a collection, but not for plain pages. That’s inconsistent. A post is really just a page which happens to be part of a collection. Maybe that can be streamlined in the future. |
What I've done in similar situations is to use |
@zellwk you might have luck with using layouts and the Layout file:
More about layouts: https://www.11ty.io/docs/layouts/ |
@zachleat Unfortunately this doesn't work because I have nested layouts. The |
I did the above (to read the file manually). It's a pretty decent solution afterall.
Would it be useful to include the solution above in 11ty docs? I'm okay with closing this issue, unless @zachleat you wanna hold this open. |
@kleinfreund what do you mean by this?
|
@zachleat If I have this shortcode: eleventyConfig.addShortcode('log_input', doc => { console.log(doc) }); and I use it inside a collection of posts for each post, I get heaps of data. All sorts of things. (Also, this object needs to lose some weight. It’s massive!). If I log it for a plain page, I get a tiny object with meta data. I believe, there shouldn’t be a difference in what I get depending on where I access it. One document model for all documents. |
@kleinfreund put another way, everything that's available about a page via a collection, should be available from the page itself, yes? Currently the |
I'm down with this |
It'd be good to have both frontmatter and content in the page itself. |
Going to continue this discussion over at new issue #338 please! |
Adding a comment here for future googlers if you don't mind – I wanted to add an "og:description" meta tag based on the content of the current blog post, but I didn't want it to include the entire content of the page. I did what @edwardhorsford suggested and looped like so in my layout:
Do let me know if there's a better way. I've tried various things but didn't find anything else that worked. Should mention that I have two levels of layout – an outer base layout and an inner blog post layout. |
I set the page's meta description to
{{description}}
. This description can be found through my frontmatter most of the time. No problems here.But I have hundreds of blog posts without this
description
property in the frontmatter. It'll take too long to go through these posts one by one. Is it possible to access page data in the frontmatter (so I can use JavaScript or shortcodes to create the description?).Here's what I did with my previous static site generator:
<!-- more -->
and format them as a description.Wondering if something like this is possible.
The text was updated successfully, but these errors were encountered: