Eleventy: Gray-matter error when using frontmatter in .njk layout

Created on 24 May 2020  路  3Comments  路  Source: 11ty/eleventy

I'll preface this with the fact I'm not sure if this is a case of the docs being wrong, or a bug in 11ty.

I'm getting an error when I try to use frontmatter in .njk files, this is what is shown in the 11ty docs, so I assume it's possible (I haven't worked with njk before)

To Reproduce

  1. Follow the docs here (https://www.11ty.dev/docs/layouts/) and create a new layout (myLayout.njk) and a new markdown file (content-using-layout.md)
  2. Use the example code from the docs for the files
  3. Run eleventy --serve
  4. See error
File added: _includes/myLayout.njk
Problem writing Eleventy templates: (more in DEBUG output)
> gray-matter engine "title: My Rad Blog ---" is not registered

`Error` was thrown:
    Error: gray-matter engine "title: My Rad Blog ---" is not registered
        at module.exports (/Users/matt/.config/yarn/global/node_modules/gray-matter/lib/engine.js:6:11)
        at module.exports (/Users/matt/.config/yarn/global/node_modules/gray-matter/lib/parse.js:8:18)
        at parseMatter (/Users/matt/.config/yarn/global/node_modules/gray-matter/index.js:109:17)
        at matter (/Users/matt/.config/yarn/global/node_modules/gray-matter/index.js:50:10)
        at TemplateLayout.read (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateContent.js:82:16)
        at async TemplateLayout.getFrontMatterData (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateContent.js:141:7)
        at async TemplateLayout.getTemplateLayoutMapEntry (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateLayout.js:55:24)
        at async TemplateLayout.getTemplateLayoutMap (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateLayout.js:66:20)
        at async TemplateLayout.getData (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateLayout.js:89:15)
        at async Template.getData (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/Template.js:244:28)
Wrote 0 files in 0.04 seconds (v0.11.0)

Expected behavior
11ty renders the markdown using the layout, as described in the docs.

Environment:

  • OS and Version: Mac 10.15.4
  • Eleventy Version 0.11.0
needs-triage

Most helpful comment

I was facing the same problem. For me, the error was occurring because the NJK prettier plugin in VS Code converted valid syntax into single line while saving.

That is

title: My Rad Blog
---

was converted to (invalid)

--- title: My Rad Blog ---

I disabled the plugin for now. However, I am looking for a better solution.

All 3 comments

I was facing the same problem. For me, the error was occurring because the NJK prettier plugin in VS Code converted valid syntax into single line while saving.

That is

title: My Rad Blog
---

was converted to (invalid)

--- title: My Rad Blog ---

I disabled the plugin for now. However, I am looking for a better solution.

I was facing the same problem. For me, the error was occurring because the NJK prettier plugin in VS Code converted valid syntax into single line while saving.

...

I disabled the plugin for now. However, I am looking for a better solution.

Oh yeah that was it! Maybe a warning could be added to the docs 馃

Facing the same issue here. Is there any beautifier can handle this properly? I am using Atom.

Was this page helpful?
0 / 5 - 0 ratings