Proposal: TOC-macros Rewrite using IF, Functions and Procedures (+new fuctionality)

A designer may very well want to do this. For example to hide welcome messages and display learning content.

@pmario et al

It seems the conversation has continued overnight my time and I am now at a disadvantage. I am ill (chest cold) and needing to prioritise something else in my life, so I cant participate fully.

  • I am not in a position to review examples and respond to specific code.

I have being pursuing conditional tocs and custom child list within them, for a long time and included needs identified, in the forums over a number of years.

  • I will try and present this below a if it was the documentation for those missing features.

I will then have to leave it with you, and hope you use the ideas.

  • I think you can see how it would be easier to explain than other alternatives in this topic. However it does not rule out also introducing include/exclude options.

pho documentation

The TOC macros build a hierarchical tree based on an initial tag, and then lists those each title is “also tagging.” The results is a hierarchical list is like the Contents tab on tiddlywiki.com. The different TOC macros present this result in different ways.

In this proposed version it is possible to modify any tiddler that appears in such a hierarchy as follows;

  • add a toc-condition field to any tiddler in the tree, default fieldname fieldname toc-condition
    • The filter within this field should either return a single result or nothing.
    • If the field does not exist or is empty it will be ignored and the title will be listed.
    • If the field exists and returns any value the title will be displayed, if no value it will not be displayed.
  • add a toc-child-filter to any tiddler in the tree, default toc-child-filter.
    • The filter here will replace the standard listing of children below the current title.
      • If you want to list the items with the current tag, you need to add this back [tag<currentTiddler>].
    • This filter can be any filter generating zero or more items to list, It can contain additional conditions that determine what to list, including their sort order.
      • Is this where the TOC iteration stops?

The default TOC makes use of the above toc-condition and toc-child-filter (or by any other name) only if they appear in the tiddlers in the generated TOC.

  • When calling any TOC macro you can configure alternate fields that play the same roles as above toc-condition-fieldname and toc-child-filter
    • This permits multiple tag hierarchies to use different fields to implement these features even when the same title exists in multiple trees, just modify the fieldnames in the TOC macro parameters.
    • If you want to override the default behaviour modify the modify the TOC macro parameters to reference non-existent condition or child-filter fieldnames.

A desirable advanced feature (no need to change the tiddler itself)

The TOC macro could be enhanced further to do the following when testing for the named fields, to allow the custom fields to be provided without editing the current tiddler.

  • Does the fieldname(s) such as toc-condition or toc-child-filter exist in the current tiddler then make use of them
    • If the fieldname(s) such as toc-condition or toc-child-filter DO NOT exist in the current tiddler, then generate the title $:/config/toc/currentTiddler` and see if that tiddler contains //fieldname// and use that if it exists.
    • Other wise proceed as normal.
  • This allows the user or designer to override the TOC behaviour without editing the tiddler itself, by creating a tiddler containing the fieldnames to be used, if they exist.

I leave this now in the lap of the gods :smile: and return to feeling miserable