I want to start off by saying that this article template (as of now) is really fricking shit. The code base is somewhat okay in complexity, but I do not feel like it is done in a efficient/good way and won't work without CSS enabled (although, most people don't disable CSS). Please use with causition until I've implemented something better that would work without CSS.
{{ toc.header("h2", "Terminology", tocList) }}Whenever I say "ToC" in this article I am refering to "Table of Contents". (I couldn't be bothered writing it out all the times...)
{{ toc.header("h1", "Usage", tocList ) }}
To use the template you would simply extend
Your content goes here
templates/article.njk
and
import components/toc.njk
:
{{ '
{% extends "templates/article.njk" %}
{% import "components/toc.njk" as toc with context %}
{% block header %}
Your header
{% endblock %}
{% block body %}
You would use the
") | replace(" ", " ") }}
header
block to define a header, and then you place your
content inside a div
with the class content
in your body
-block.
Adding headers is kind of easy, {% raw %}{% import "components/toc.njk" as toc with context %}{% endraw %}
imports a macro that will create a header and automatically add it to the table of contents. You use it as such:
{{ '{{ toc.header(size, text, tocList) }}' }}
size
is a string and is a header level (aka h1
, h2
, h3
, etc.),
text
is a string that holds the text you would want to display, and finally tocList
is a
variable inherited from template/article.njk
that keeps a hold of which headers should go in the ToC.
If you would want to display an {{ '
with the text "Introduction" you would do:
' }}
{{ '{{ toc.header("h1", "Introduction", tocList) }}' }}
Sadly it isn't enough to just add the heading to the ToC. You will have to generate the ToC as well, but
this isn't hard at all to do. You simply add {{ '{{ toc.generate(tocList) }}' }}
to the end
of your body
-block.
{{ '
{% extends "templates/article.njk" %}
{% import "components/toc.njk" as toc with context %}
{% block header %}
Your header
{% endblock %}
{% block body %}
{{ toc.header("h1", "Introduction", tocList) }}
Your introduction goes here...
{{ toc.generate(tocList) }}
{% endblock %}' | escape | replace("\n", "", 1) | replace("\n", "
") | replace(" ", " ") }}