How to do a table of contents in text pattern

My teaching pages are served out using Textpattern, a relatively light CMS that uses textile wiki-like markup.

Because adding an excerpt by hand wrecks the syndication of this site through Wordpress to my other blog, I don’t usually add a text summary. Instead, I do something similar to the Wikipedia or Wordpress: I begin articles with an abstract like first paragraph, then include a table of contents, then have the rest of the body.

I used to make up these tables of content by hand, cursing all the time that Textile wasn’t XML. Then I discovered soo_toc, a Textpattern plugin that builds tables of contents dynamically. Joy!

Of course, now I need to remember to add the template that calls the TOC to each page (as I type this, I wonder if there might not be a simple variable I could develop that does this, but that’s for later). In the interests of remembering, here it is:

<div id="TOC">
   <txp:soo_toc label="Contents" labeltag="h3"/>
</div>

The only downside of this plugin is that you need to have IDs attached to every header you want to show up in the TOC. You add an ID in textpattern like this: h2(#IDREF). If you are in a rush, you can always just use (#A), (#B), (#C) (remember, IDREFs can’t start with a number in XML).

tags: , , ,


Follow

Get every new post delivered to your Inbox

Join other followers: