-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Can’t access markdown frontmatter data within _template.jsx #676
Comments
_template files are for parts of site that are shared across pages e.g. the classic example would be a header. Wrappers are to “wrap” data from static files inside react components as in Gatsby, every page has to eventually be a React component. The markdown wrapper (and other wrappers) is called for every markdown file. Nested _template files are useful if a sub-section of the site has its own navigation or other shared section. The left sidebar on the docs section of the documentation starter is an example http://gatsbyjs.github.io/gatsby-starter-documentation/docs/ && https://github.com/gatsbyjs/gatsby-starter-documentation/blob/master/pages/docs/_template.jsx |
I'm on the same situation. Regards |
I found a way to get the required data in the template, but it is a bit ugly. I noticed that the children has a props property, which in turn has a route that holds all the page information. So you can do this from the template: Regards |
@danielo515 if you want to add a PR to pass the page data directly to templates as well, we could add support for that. |
Just want to add a 👍 to this proposal. I only just started experimenting with Gatsby so I'm not terribly familiar with it yet, but coming from using Jekyll, this is one of the first things that I tried to do. Hence landing on this thread. It seems natural that the template should know about the properties of its content, in order to keep display logic related to that content in the same place. |
Dear @KyleAMathews that will be cool. Where should I start looking at ? |
@danielo515 of it's already there haha, I haven't used Gatsby 0.x forever. checkout |
Dear @KyleAMathews , I checked already, and I saw it, but that requires an, in my oppinion, unnecessary filtering. Don't get me wrong, having that information is very useful, but I would like to have something easier to access tho the data of the current page, like |
Hey! |
@danielo515 collateral :-) though picking good libraries with good designs mean you inherit lots of goodies that fall out of their good design. |
I want a way to render the title, date and author of a blog post from the markdown front matter. It seems like a template would be a natural way to solve this use case:
However, as far as I can see, the front matter data properties are not exposed to the template.
The supported solution, AFAIK, is to use the wrapper a la #135
/wrappers/md.js
To do so, I must implement ugly branching logic within that file to first check I am under the /blog/ path, and then I can implement my template with the data made available to
this.props.route.page.data
Since paths are just based on the file structure anyway, using the template file for this use case seems much more natural. As it stands, I am left scratching my head as to what the purpose of nested _template.jsx files even is.
The text was updated successfully, but these errors were encountered: