eleventy
eleventy copied to clipboard
Selective content for each block
Hi, thank you for this wonderful tool.
I have a question on whether I can have a selective block appearing on only 1 part of the layout.
Specifically, I have this:
layout.njk with the following content:
---
#some front matter here
---
{%- if header %}
{% block header %}
{{ content | safe }}
{% endblock %}
{%- endif %}
{%- if references %}
{% block references %}
{{ content | safe }}
{% endblock %}
{%- endif %}
Then I have example.html with this info:
---
#some front matter
---
{% block header %}
<div>This is the header</div>
{% endblock %}
{% block references%}
<div>this is the references</div>
{% endblock %}
What I want to do is to have <div>This is the header</div> only shows in the block header and <div>This is the references</div> appeared in the block reference only. Right now, it just generate an HTML file with both divs in each block
result.html:
...
<div>This is the header</div>
<div>This is the references</div>
<div>This is the header</div>
<div>This is the references</div>
I was wondering if this could be achieved with 11ty? Perhaps I don't have the layout.njk correctly set up?
Thank you very much!