Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TiddlyWiki: Filter table of contents by multiple tags

I have a tiddlywiki with multiple roleplay game notes in it. Every tiddly is tagged with its respective game name and a category (e.g. "city" or "NPC").

Now I want to create a table of contents that list only, for example, NPCs of one game. And I would like to do it with the toc.

My current code is this:

<div class="tc-table-of-contents">
<<toc 'NPC'>>
</div>

However, this gives me ALL NPCs. How can I add another tag as filter criteria?

like image 387
GrazingScientist Avatar asked Nov 16 '22 00:11

GrazingScientist


1 Answers

Presumably too late to help you out, but for anyone else who happens upon this question, the sort parameter of the toc macro can include an arbitrary filter step or steps, so you can do:

<div class="tc-table-of-contents">
<<toc 'NPC' sort:"tag[SecondTag]">>
</div>

See Table-of-Contents Macros for a full description of the options for toc and its siblings.


If you want the filter to match multiple criteria ANDed together, you can say, e.g., tag[one]tag[two]. An OR condition isn't really designed to work here, though, as you need multiple filter runs to do an OR condition in a filter, and the sort command is expecting only filter steps.

Here's a hack that appears to work for an OR condition as of 5.1.23:

<div class="tc-table-of-contents">
<<toc 'TableOfContents' sort:"tag[one]][all[shadows+tiddlers]tag<__tag__>!has[draft.of]tag[two]">>
</div>

However, this is essentially doing an injection attack on the toc macro, so I wouldn't trust it to continue working if I were you. If you need something this complicated, you would probably be better rigging something up yourself with a $list widget or three than trying to use the toc macro.

like image 52
Soren Bjornstad Avatar answered Dec 27 '22 05:12

Soren Bjornstad