-
-
Notifications
You must be signed in to change notification settings - Fork 475
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
Is it possible to use data in front matter? #216
Comments
We did play around with a feature to do this for awhile (and it’s undocumented) but I wasn’t real happy where it landed and now I think it’s mostly eclipsed by JavaScript data files. You can do any manner of variable reuse in there. You can use JS Data Files alongside front matter, if you’d like, although you wouldn’t be able to use your front matter to set values in your JS Data Files. |
Thanks for the fast reply. I don't think data files fully achieve what I want - which is to be able to make use of front matter from posts in intermediary templates to set values on my base template. That or I'm not getting it. I've just tried with a {
"bodyClasses": "post post__{{page.fileSlug}} + {{pageClasses}}",
"permalink" : "/{{page.fileSlug}}/index.html"
} Both page.fileslug and pageClasses get printed as strings. I've also tried using |
Oh, hmm. Yeah I see the value there. Just for the record, you can achieve something similar without leaning so heavily on front matter. Base template
Post templateSet
Individual post
Does that do what you need? |
It does for this use case (I went for something similar to this already), but I was aiming for less template specific stuff in my base template. My class structure may change per category, so having {{pageType}}__{{page.fileSlug}} isn't necessarily universal. Right now it just means I'll have several variables in that base template. Not an a big issue though - just a neatness thing. FWIW I feel there would be value in being able to concatenate / otherwise use existing data in frontmatter. I can see people using |
Watch for the |
Hey @zachleat! I'm hesitant with Being able to directly use variables would be much nicer. It sounds like that's too hard though. Better to have a way of doing it though. |
Related: upvotes needed at #335 |
Hey @zachleat, are we still unable to access front matter data in JS data files? Is there any chance this will be added in the future? |
New in v0.11.0 it's now possible to use the ---
eleventyComputed:
bodyClasses: "post post__{{page.fileSlug}} {{pageClasses}}"
--- |
Is it possible make use of data in front matter? or use existing front matter in other front matter?
My template order is roughly
post > post template > base template
. I'd like to be able to set things in frontmatter that 'trickle up' - and can be used by other frontmatter. Or use a data variable inside of front-matter.What I'd like:
Base template:
Post template:
Individual post:
At the moment it looks like
{{pageClasses}}
gets printed as a string rather than interpreted.So I get this:
<body class="post post__{{page.fileSlug}} {{pageClasses}}">
Rather than:
<body class="post post__amazing-url foobar">
Context: I'm new to front matter, so perhaps this just isn't something it's designed for. Any suggestions you have would be welcome. I note that permalinks seem to be able to use variables, so I assume it's not completely impossible for frontmatter to contain them.
The text was updated successfully, but these errors were encountered: