Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to check if toc is empty #154

Open
njanakiev opened this issue Apr 11, 2022 · 2 comments
Open

Add flag to check if toc is empty #154

njanakiev opened this issue Apr 11, 2022 · 2 comments

Comments

@njanakiev
Copy link

First of all thanks for the great project! I think an useful feature might be to have a flag to see if the table of contents is empty. Perhaps something in this direction:

{% if not toc.empty %}
<h2>Table of Contents</h2>
{% endif %}

This could be useful for short articles that do not require a table of contents.

@rathboma
Copy link

rathboma commented Feb 8, 2023

Yes! I definitely need something like this. I have an empty 'on this page' block otherwise.

@markdboyd
Copy link

For what it's worth, this seems to work for conditionally rendering the TOC on my pages:

        {% assign toc_content = content | toc_only | strip %}
        {% if toc_content != '' %}
          <h2>Table of Contents</h2>
          <div id="table-of-contents">
            {{ toc_content }}
          </div>
        {% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants