eleventy
eleventy copied to clipboard
blocks and frontmatter being ignored
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 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 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.
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