I use
<div class="tc-table-of-contents">
<<toc "Inhalt">>
</div>
where every tiddler tagged with Inhalt is listed in toc. This works fine.
But I have an additional tag named Fahrt. Is it possible to change the color in the toc of this entries? The result should look like this:
Only tag Inhalt --> normal blue color
tag Inhalt + tag Fahrt --> perhaps a lighter blue oder different color
This isn't possible with the default
tocmacros, but we can write a new macro based on the built-intocmacro to do this without too much trouble. We'll make a version of the macro,template-toc, that uses a template to display each element in the table of contents – this way, we'll be able to reuse our work to format TOC elements in a totally arbitrary way. (Fuller explanation of templates. NB: I wrote this.)We first start by copying the macros
tocandtoc-bodyfrom$:/core/macros/tocand pasting them into a new tiddler$:/template-toc-macros(you can call this tiddler anything you want) with the tag$:/tags/Macro(this will cause the macros in it to be available in any tiddler in the wiki).Then we rename
toc-bodyand all references totemplate-toc-body, likewisetoctotemplate-toc. We add a parametertemplateas the second parameter of both of these macros, and adjust the bodies of both so that they transclude the<<__template__>>parameter as a tiddler rather than looking into thecaptionandtitlefields for a title and creating a link with this as the text. That makes the body of this tiddler look like this:Now here's how we use this: we create a template tiddler which, given that the variable
<<currentTiddler>>is set to a particular tiddler we want to include in the TOC, renders the HTML/wikitext we want to include in the table of contents. In this example, we'll call this tiddlerMyTemplate, but you'll probably want to use something more descriptive. In your case, the text will look something like:That is, if the filter
[all[current]tag[Fahrt]]has any output, i.e., thecurrentTiddleris taggedFahrt, then fill in the body of the$listwidget (creating a span with acolor: red;CSS property), containing thecaptionfield if it exists on the tiddler, or thetitlefield otherwise. If it's not taggedFahrt, then fill in the contents ofemptyMessage, which does the same thing but without the color. In either case, create a link going tocurrentTiddlercontaining that content.Lastly, wherever you want to show the table of contents, call the
template-tocmacro instead of thetocmacro, and pass it the template you just created as a second argument:Result: