I want to create a table of contents and endnotes in a Jinja2 template. How to complete these tasks?
For example, I want to have the following template:
{% block toc %}
{
{% endblock %}
{% include "some other file with content.jnj" %}
{% block endnotes %}
{
{% endblock %}
Where some other file with content.jnjhas such content:
{% section "One" %}
Title information for Section One (may be quite long); goes in Table of Contents
...
Content of section One
{% section "Two" %}
Title information of Section Two (also may be quite long)
<a href="#" id="en1">EndNote 1</a>
<script type="text/javsacript">...(may be reasonably long)
</script> {# ... Everything up to here is included in the EndNote #}
Where I say "can be quite / reasonably long", I want to say that it cannot be quoted as an argument for a macro or global function.
I am wondering if there is a sample for this that can accommodate this, as part of Jinja2.
My initial thought is to create an extension so that you can have a block for sections and end notes, for example:
{% section "One" %}
Title information goes here.
{% endsection %}
{% endnote "one" %}
<a href="#">...</a>
<script> ... </script>
{% endendnote %}
Then the global functions are performed (which pass in the Jinja2 environment):
{{ table_of_contents() }}
{% include ... %}
{{ endnotes() }}
However, although this will work for endnotes, I assume a second pass is required for the table of contents.
. .