-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
how to access directory specific data from a template in that directory #385
Comments
What’s your |
|
Edit: 2019/02/09 (10:20 AM EST) Edit: 2019/02/09 (10:55 AM EST) File structure:
{
"name": "Raymond Jones",
"expertise": [
{
"name": "Front End Development",
"skills": [ 'HTML', 'CSS', 'JavaScript' ]
},
{
"name": "Web Design",
"skills": [ 'Sketch', 'InDesign', 'Photoshop' ]
}
]
}
<p>Hi, my name is {{ about.name }}!</p>
<p>My expertise:</p>
<ul>
{% for expertise in about.expertise %}
<li>{{ expertise.name }}</li>
{% endfor %}
</ul>
<p>My skills:</p>
<ul>
{% for expertise in about.expertise %}
{% for skill in expertise.skills %}
<li>{{ skill }}</li>
{% endfor %}
{% endfor %}
</ul> Does that help? |
Hey Paul, thanks for this. I've tried it with no luck, though. Might there be something I'm missing from my config or frontmatter? |
What specifically isn't working? Does the page get generated in your output folder? The dynamic values aren't there? |
Sorry, I had a couple typos. Here's the corrected code.
{
"name": "Raymond Jones",
"expertise": [
{
"name": "Front End Development",
"skills": [ "HTML", "CSS", "JavaScript" ]
},
{
"name": "Web Design",
"skills": [ "Sketch", "InDesign", "Photoshop" ]
}
]
}
---
title: About
slug: about
---
<p>Hi, my name is {{ name }}!</p>
<p>My expertise:</p>
<ul>
{% for expertise in expertise %}
<li>{{ expertise.name }}</li>
{% endfor %}
</ul>
<p>My skills:</p>
<ul>
{% for expertise in expertise %}
{% for skill in expertise.skills %}
<li>{{ skill }}</li>
{% endfor %}
{% endfor %}
</ul> |
This is a working example of how to access directory specific data from a template in that directory when using Eleventy: https://github.com/paulshryock/eleventy-page-data |
Ahh, so it's the |
I hadn't mentally made that connection, but you could be right. I was thinking the files just need to be in the same directory. @zachleat, any insight on which it is? |
Apologies if this is a dupe issue, I've been unable to find what I'm looking for here (closest thing seems to be #273) or in the docs (I would've expected it to be on the template and directory data files page. Alternatively, maybe I'm mistaken about the point or role of directory/template data files.
I've got an "About" page on a site I'm working on, built from the files in an
about
folder, in which there's anindex.liquid
file and anabout.11tydata.js
file, from which I export an array of items that I want to iterate through in theabout/index.liquid
file. How might I accomplish this? I was under the impression that having a data file in a template directory would expose the data to the template in that directory (and only that (or those) template(s)). But it's unclear, to me at least, how that data is exposed in the template.Thanks, cheers, and ❤️
The text was updated successfully, but these errors were encountered: