Skip to content
Discussion options

You must be logged in to vote

I believe that Eleventy only supports .json and .js data files by default.

With that in mind, the way I would go about this would be to create a global data file, something likeyamlData.js.
In this I'd create an array, then I'd loop over all your yaml files, read them (using fs) and parse them to a JS object using js-yaml in a format something like like :

{ 
 name: <filenameWithoutExtension>
 data: <parsed YAML>
}

Then add each object to your array. If you export this array from yamlData.js it will be available to your templates as yamlData Then you just need a template something similar to :

---
pagination:
  data: yamlData
  size: 1
  alias: item
permalink: "{{ item.name }}.html"
---

{…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hoanguyenn2015
Comment options

@dwkns
Comment options

Answer selected by hoanguyenn2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants