Conditionally check for TOC #34
Answered
by
allejo
jeremyzilar
asked this question in
Q&A
-
Public Repo https://github.com/brooklynrail/brooklynrail-handbook/ Description I would like to be able to wrap the TOC is some markup.
but I am having a hard time figuring out how to conditionally check to see if there is a TOC, or if there are headings on the page. The problem is that the TOC Do you mind pointing out where I would conditionally check for the TOC in the file? |
Beta Was this translation helpful? Give feedback.
Answered by
allejo
Apr 16, 2020
Replies: 2 comments
-
Untested code but you'd want to use the following logic:
{% capture page_toc %}
{% include toc.html html=content %}
{% endcapture %}
{% assign page_toc = page_toc | strip %}
{% if page_toc != "" %}
<div class="toc">
<h2>On this page</h2>
{{ page_toc }}
</div>
{% endif %} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
allejo
-
Thanks. I’ll give that a try |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Untested code but you'd want to use the following logic:
<div>
and use the TOC that was captured