Skip to content
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

Layout front matter data not available when setting a template's layout through a global data file or a directory data file #2163

Closed
Gadiguibou opened this issue Jan 9, 2022 · 1 comment
Assignees

Comments

@Gadiguibou
Copy link

Gadiguibou commented Jan 9, 2022

Describe the bug
Layout front matter data is incorrectly merged with template front matter data when the layout property is in a global data file, for example, "_data/layout.json".

To Reproduce
Steps to reproduce the behaviour:

  1. Create a new empty eleventy project.

  2. Create a new layout _includes/my_layout.liquid with contents:

    ---
    test: test
    ---
    <h2>Content from the layout is displayed</h2>
    {{ content }}
    
  3. Create a global data file _data/layout.json with contents: "my_layout.liquid".

  4. Create a new template index.liquid with contents:

    ---
    # layout: my_layout.liquid
    ---
    <h1>Value of "test" from layout front matter data: {{ test }}</h1>
    
  5. Serve the site and notice that the rendered HTML is <h2>Content from the layout is displayed</h2>\n<h1>Value of "test" from layout front matter data: </h1>.

Expected behaviour
The value of "test" should be displayed in the <h1> element.
This is made evident by the behaviour when the layout is explicitly specified in the template (by uncommenting the line in the front matter of index. liquid for example).

Screenshots
When setting the layout using a global data file:
image
When setting the layout using the template's front matter:
image

Environment:

  • OS and Version: Linux (Pop!_OS/Ubuntu) 21.10
  • Eleventy Version: 1.0.0

Additional context
The bug also appears when setting the layout property using the following:

  • a directory data file
  • a global data file
  • the configuration API's addGlobalData

The bug does not appear when setting the layout property from the following:

  • frontmatter data in the template
  • a template data file
@zachleat
Copy link
Member

I believe this is a duplicate of #2145, whose fix will ship with 1.0.1—thank you!

@zachleat zachleat self-assigned this Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants