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

Do not render the TOC if it is empty #6

Closed
tomzx opened this issue Oct 23, 2015 · 2 comments
Closed

Do not render the TOC if it is empty #6

tomzx opened this issue Oct 23, 2015 · 2 comments

Comments

@tomzx
Copy link
Contributor

tomzx commented Oct 23, 2015

I have a blog where I force the TOC to render since the [TOC] macro is not part of the article's content.

{{ ('<p>[TOC]</p>'~page.content)|toc }}

However, I'd like it if the TOC didn't render anything if the table was empty. Is there any way to make that possible?

Thanks!

@Sommerregen
Copy link
Owner

HI @tomzx , I guess that's something I have to update. Instead of L251 you may try this (untested).

$toc = $this->createToc($content);
// Don't process TOC if there aren't any headings in the content
if (empty($toc)) {
  return $content;
}

@tomzx
Copy link
Contributor Author

tomzx commented Oct 23, 2015

@Sommerregen Thanks!

@tomzx tomzx closed this as completed Oct 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants