Is it possible to generate multiple pages with the same multiple data files? #3908
-
|
Hello, I have many data files (file1.yml, file2.yml, ...) that need to generate page1, page2, and so on. https://www.11ty.dev/docs/pages-from-data/ does mention about one data file to many pages, not my use case. My YML files have a similar structure, but not all the same; some have 5 keys, some have 40, etc. key1: data1
key2: data2
key3: data3
...
key900: data900 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
I believe that Eleventy only supports With that in mind, the way I would go about this would be to create a global data file, something like {
name: <filenameWithoutExtension>
data: <parsed YAML>
}Then add each object to your array. If you export this array from ---
pagination:
data: yamlData
size: 1
alias: item
permalink: "{{ item.name }}.html"
---
{% for key , value in item.yamlData %}
<li>{{ key }} - {{ value }}</li>
{% endfor %}And it will create a page for each item in the array and you can use your YAML keys & values as required. Does that make sense? |
Beta Was this translation helpful? Give feedback.
I believe that Eleventy only supports
.jsonand.jsdata files by default.With that in mind, the way I would go about this would be to create a global data file, something like
yamlData.js.In this I'd create an array, then I'd loop over all your
yamlfiles, read them (using fs) and parse them to a JS object usingjs-yamlin a format something like like :Then add each object to your array. If you export this array from
yamlData.jsit will be available to your templates asyamlDataThen you just need a template something similar to :--- pagination: data: yamlData size: 1 alias: item permalink: "{{ item.name }}.html" --- {…