Filter needed to get all tiddlers shown in a TOC

For example, if we go to tiddlywiki.com and open TableOfContents tiddler, it shows a toc macro displaying all the child tiddlers/nodes.
Is there any filter available to get all these child tiddlers as seen when using the toc macro, so that I can do selective operations like export.

see TiddlyTools/TOC, specifically the toc-list macro, which is very compact, and is shown here in its entirety:

\define toc-list(here,max,exclude,level:"1",field:"tags")
<!-- SHOW FLAT LIST -->
<$list filter="""[contains:$field$[$here$]sortby{$here$!!list}] -[subfilter<__exclude__>] -[[$here$]]""">
   <$text text="[["/><<currentTiddler>><$text text="]]"/><br>
   <$reveal default="$level$" type="nomatch" text="$max$">
      <$macrocall $name="toc-list" here=<<currentTiddler>> max="$max$" exclude="""$exclude$ [[$here$]]""" level={{{ [[$level$]add[1]] }}} field=<<__field__>>/>
   </$reveal>
</$list>
\end

The only required parameter is here, which is the “root tiddler” for the TOC.

optional parameters include:

  • max = maximum tree depth to show
  • exclude = a title list or filter expression for tiddlers to omit from the output
  • field = field name of the list of “parent” tiddlers for each tiddler in the tree.
    Note that level is only set and used internally to enable the max param to work.

To capture the toc-list output in a variable and then export to a file, you will need to use $wikify and tm-download-file, like this:

<$wikify name="tids" text="<<toc-list SomeTag>>">
<$button> download TOC
<$action-sendmessage $message="tm-download-file" $param="$:/core/templates/exporters/JsonFile" exportFilter=<<tids>> filename="tiddlers.json" />
</$button>
</$wikify>

enjoy,
-e

1 Like

addendum:

You can also drag-and-drop the list of tiddlers to another TiddlyWiki, without needing to first export them to an external .json file. Simply add dragFilter=<<tids>> as a parameter in the $button widget. You can then drag the button to another TiddlyWiki. When you drop it, the TWCore standard $:/import tiddler will be displayed, listing all the tiddlers collected by the toc-list macro.

enjoy,
-e

1 Like

I actually want it as filter to be used in the flex-card-macro from the tiddlywiki.com like shown below

<div class="tc-cards">
<$list filter="[tag[HelloThumbnail]]">
<$macrocall $name="flex-card" captionField="caption" descriptionField="text"/>
</$list>
</div>

Is that possible ?

Once you’ve used $wikify to capture the output of the toc-list macro into a variable, you can then use enlist<varname> in your filter, like this:

<$wikify name="tids" text="<<toc-list HelloThumbnail>>">
<div class="tc-cards">
<$list filter="[enlist<tids>]">
<$macrocall $name="flex-card" captionField="caption" descriptionField="text"/>
</$list>
</div>

Note also that others have created some custom filters that will perform the “tree walk” recursion using javascript.

Specifically, @Yaisog has created the taggingtree[] filter (see Recursive filter operators to show all tiddlers beneath a tag and all tags above a tiddler), and @bimlas has created the kin[] filter (see TW5 Kin filter plugin — recursively looking for kinship between tiddler titles).

While each of these solutions will work for your use-case, they may exhibit different performance characteristics, depending upon the complexity of the TOC that you are applying it to.

In particular, since the TiddlyTools toc-list macro relies upon $wikify to store the output in a variable, it might be a bit slower than the javascript-based solutions mentioned above, but I’ve seen reasonably good performance, even when processing relatively “deep” TOC trees such as the TableOfContents on TiddlyWiki.com. You’ll just have to experiment a bit to see if this is an issue for you

One notable advantage of the TiddlyTools toc-list macro is that it only uses wikitext to achieve it’s results, without needing to install custom javascript filter code. This makes it easier to use in public TiddlyWikis that are hosted online simply by importing a few tiddlers without needing to save-and-reload a local copy before they can be used.

-e

1 Like

Thanks @EricShulman for the detailed explanation…i will test it out when I am back on my desktop today night.

It works well. I will have to check the performance issues once my wiki become large. Currently no such issues in my tests

Thank you @EricShulman
The toc-list is really useful, specially for exporting tiddlers. This is the same code but uses TW 5.3.x features.

\procedure toc-list(here,max,exclude,level:"1",field:"tags")
<!-- SHOW FLAT LIST -->
	<$list filter=`[contains:$(field)$[$(here)$]sortby{$(here)$!!list}] -[subfilter<exclude>] -[<here>]`>
		<$text text={{{ [<currentTiddler>format:titlelist[]]}}}/><br>
		<%if [<level>!match<max>] %>
			<$transclude $variable="toc-list" here=<<currentTiddler>> max=<<max>> exclude=`$(exclude)$ [[$(here)$]]` level={{{ [<level>add[1]] }}} field=<<field>>/>
		<%endif%>
	</$list>
\end

As with my earlier comment on our default toc macros: is there any reason that the “here” parameter should need to be specified every time, rather than defaulting to the current tiddler? It seems this approach (letting current tiddler be the default) would make it very flexible and intuitive as part of a view template…

I’ve just updated https://tiddlytools.com/#TiddlyTools%2FTOC so that the here param is no longer REQUIRED, and will default to the <<currentTiddler>> value if not specified. This change applies to <<toc-tree>, <<toc-all>>, and <<toc-list>> macros.

enjoy,
-e

2 Likes