eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

blocks and frontmatter being ignored

Open tcurdt opened this issue 5 years ago • 2 comments

I got the following chain of layouts:

base.njk

<body>
tech=[{{tech}}]
post=[{{post}}]
{% block content %}{% endblock %}
</body>

tech.njk

---
tech: a
---
{% extends "layouts/base.njk" %}
{% block content %}
{% block post %}{% endblock %}
{% endblock %}

post.njk

---
post: a
---
{% extends "layouts/tech.njk" %}
{% block post %}
{{ content | safe }}
{% endblock %}

I would have expected the frontmatter to be merged as documented and see tech=[a] post=[a] instead I am seeing tech=[] post=[a]. Is that a bug? Or me having wrong expectations?

tcurdt avatar Mar 22 '20 16:03 tcurdt

@tcurdt I'd have to try recreating it locally to test it, but are you setting eleventyConfig.setDataDeepMerge(true) in your Eleventy config file?

https://www.11ty.dev/docs/data-deep-merge/

pdehaan avatar Mar 22 '20 17:03 pdehaan

@pdehaan I didn't and I just wanted to write "I knew I must have missed something!" But even after enabling it I am still seeing the same behaviour :-/

I am wondering whether this is due to the switch to using extends.

tcurdt avatar Mar 22 '20 17:03 tcurdt

I see a similar misunderstanding in your other issue here: https://github.com/11ty/eleventy/issues/1112#issuecomment-3560622355

{% extends %} doesn’t use or populate the Eleventy Data Cascade. The front matter is discarded entirely there. You’ll need to make use of Eleventy Layouts to unlock Data Cascade use (or use another mechanism like {% set %} to set data in tech.njk

https://www.11ty.dev/docs/layout-chaining/#addendum-about-existing-templating-features

zachleat avatar Nov 21 '25 14:11 zachleat