-
Hi all. What I want: Ways to expose variables from within filename: blog/post.md
---
layout: _include/layout.njk
---
{% set tableOfContents %}
[[toc]]
{% endset %}
## Heading
{% set mainSnippet %}
\```tsx
const Component: React.FC = () => <div></div>
\```
{% endset %}
filename: _include/layout.njk
{{ tableOfContents }}
<article>
</article>
<div class="main-snippet">
{{ mainSnippet }}
</div> filename: _site/blog/post.html
<div class="table-of-contents">
<ul>
<li><a href="#heading">Heading</a></li>
</ul>
</div>
<article>
</article>
<div class="main-snippet">
<code>
<pre><span>const</span> <span>Component</span></pre>
</code>
</div> I've went through all of 11ty and nunjucks docs and couldn't find a good way to do this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
As far as I understand, if you use
I'd have to try building everything locally, but I think the general syntax is something like this: ---
# filename: blog/post.md
---
{% extends "layout.njk" %}
{% block tableOfContents %}
[[toc]]
{% endblock %}
{% block content %}
## Heading
{% endblock %}
{% block mainSnippet %}
\```tsx
const Component: React.FC = () => <div></div>
\```
{% endblock %} ---
# filename: _include/layout.njk
---
{% block tableOfContents %}{% endblock %}
<article>
{% block content %}{% endblock %}
</article>
<div class="main-snippet">
{% block mainSnippet %}{% endblock %}
</div> |
Beta Was this translation helpful? Give feedback.
As far as I understand, if you use
{% set %}
in a template, the variable is local to that template, and doesn't pass around like if it was defined in front matter or in a directory/template data file. I can think of the following two suggestions/ideas:{% block %}…{% endblock %}
tag to make blocks of content.I'd have to try building everything locally, but I think the general syntax is something like this: