eleventy
eleventy copied to clipboard
Using Nunjucks blocks from within Markdown
I'd like to be able to assign content in a Markdown source file to a Nunjucks block.
page.njk:
{% block main %}{% endblock main %}
page.md:
{% block main %} This is some sample text. {% endblock main %}
The thought is that the template could be set up to accommodate named sections of content that could be written in Markdown.
page.njk:
`
... `
page.md:
` {% block main %} This is some sample text. {% endblock main %}
{% block section1 %} This is some more sample text. {% endblock section1 %}
... `
This is currently doable, but you need to use Nunjucks {% extends %} instead of Eleventy layouts.
Is this still doable? I just had it working and suddenly it stopped.
(Using 11ty v.1.0.2) Just to share my case, hope this helps.
I've a a page that uses a specific layout in my FrontMatter:
layout: layouts/article-container-layout.html
that is based upon another "base" layout (a more general one).
In the page I use the block syntax to have the opportunity to substitute content. But it does not function. The block are never substituted.
I change my definitions in my FrontMatter as per @dz4k suggestion:
extends: layouts/article-container-layout.html
The engine processed the blocks, but unluckily lost all the layout. I wish I could combine both... as Nunjucks is capable to do.
Is there a way to obtain this? Thanks in advance.
Sorry for the super late reply here but Markdown is preprocessed by Liquid by default (not Nunjucks).
You’ll likely need to use https://www.11ty.dev/docs/config/#default-template-engine-for-markdown-files to change this setting to Nunjucks instead. Then you’ll be able to use blocks as expected (in the same file)