11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.

Home Page:https://www.11ty.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

frontmatter data parsing / not responding on njk file.

damianroiz opened this issue · comments

Describe the bug
when I turn a html into njk and add frontmatter data to it, it is not passing through, and it is parsing on top of the file like with the --- turning into -- - like in this example:

-- -title : 'example'
layout : 'base.njk'


This issue is not happening on the _includes files

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
I just want the frontmatter data to remain in this format and its information to be passed through the file, (in this example, I want to be able to see the title change browsed)


title : 'example'
layout : 'base.njk'

Screenshots
If applicable, add screenshots to help explain your problem.

Environment:

  • OS and Version: [e.g. Windows/Mac/Linux]
  • Eleventy Version [via eleventy --version or npx @11ty/eleventy --version]

Additional context
Add any other context about the problem here.

@damianroiz Do you have a public repo or something where this is happening?

Only thing I can think of is this note in the 11ty Nunjucks docs:

{% include 'included.njk' %} looks in _includes/included.njk. Filenames must be in quotes. Does not process front matter in the include file.

The other thing I would mention here is that you cannot use front matter inside of includes?

I don’t think this test case has enough info to reproduce—sorry!

Please attach a test case and we can revisit!

This is an automated message to let you know that this issue requires additional input from the original poster and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

Do not let the issue’s closing deter you. After you’ve supplied the required information, the issue will be reopened. Thanks!

Hello,

Thank you for your reponse, you can check this repo here with one file in which the frontmatter data is parsed:

It seems I have some auto-formater like Prettier could be causing this....

Yeah, I see it in the https://github.com/damianroiz/11ty-blog/blob/86fb59084c401b7a8bbb06556c5703f58a2385bf/src/_includes/article.njk#L1-L2 layout too.

If you manually fix it and save your files, does it auto reformat again? I think you're right and it could be some VS Code setting.

@pdehaan I have just found the issue on a similar post in SoF, I followed this exact answer (option 2) and the parsing issue seems to have been resolved. Thanks for following up!