Skip to content

Expose data from within markdown? #2521

Answered by pdehaan
ruiconti asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  1. If possible, set the [simple] values in front matter if you want to consume them in other templates/layouts.
  2. Use something like Nunjuck's {% 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:

---
# filename: blog/post.md
---

{% extends "layout.njk" %}

{% block tableOfContents %}
  [[toc]]
{% endblock %}

{% block content %}
## Heading
{%

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ruiconti
Comment options

@pdehaan
Comment options

@pdehaan
Comment options

@ruiconti
Comment options

Answer selected by ruiconti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants