I am a self confessed webtard so go easy. Using Jekyll I have a site where the content is pumped through a liquid filter to generate a table of contents. The default.html file contains a little something like this . . .
<div id='content'>
{{ content | toc }}
{{ content }}
</div>
How can I use the yaml front matter (with something like do_toc: true) to make the table of contents appear only on specified pages?
You probably want to define a different layout for those pages that need the table of contents and those that don’t. It sounds like you are using
default.htmlas the template for all your content. Instead, make a copy ofdefault.htmlcalled something else, e.g.toc.html, and then edit that file (erg, that does mean you’ll have to edit in HTML) to have thedivblock you provide where you want it.Then in pages that need toc, in the yaml header, just use
instead of
Note: There’s no need to copy
default.html. Simply add create a file namedtoc.htmlto your_layoutsdirectory with the following contents:and then write your yaml headers for your pages as shown. No duplication of HTML at all.