Macro: Produce a Delimited List

It has been asked several times in the forum: how to produce a list as a comma separated, or pipe separated, etc.

Here I propose some solution and welcome contributions and experiences for such cases.

1 Like

Case 1: Output is a list of text values

Here only a text (static) values are required with a delimiter!

  1. Goto https://tiddlywiki.com/
  2. Create a new tiddler
  3. Tag it with $:/tags/Macro
  4. Put the below script and save
\define dlist(filter, delimiter:", ")
<$list filter="$filter$ +[join[$delimiter$]]">
<$text text=<<currentTiddler>> />
</$list>
\end

Testing

  1. Create a new tiddler
  2. Display the first four tiddler titles tagged with Learning and separated with comma!
<<dlist "[tag[Learning]limit[4]]">>

produces

Videos, Introduction to filter notation, Sharing a TiddlyWiki on Dropbox, Sharing your tiddlers with others
  1. Display the list of tiddler titles tagged with About and separated with pipe (|)!
<<dlist "[tag[About]]" " | ">>

produces

Acknowledgements | Contributors | History of TiddlyWiki | License | Releases | RoadMap

Case 2: Output is a list of link values

Here the outputs are links and separated with specified delimiter

  1. Goto https://tiddlywiki.com/
  2. Create a new tiddler
  3. Tag it with $:/tags/Macro
  4. Put the below script and save
\define dlist-link(filter, delimiter:", ")
<$list filter="$filter$ +[butlast[]]"><$link/>$delimiter$</$list>
<$list filter="$filter$ +[last[]]"><$link/></$list>
\end

Testing

  1. Create a new tiddler
  2. Display the first three tiddler titles tagged with Learning and separated with comma!
<<dlist-link "[tag[Learning]limit[3]]">>

produces

Videos, Introduction to filter notation, Sharing a TiddlyWiki on Dropbox

  1. Display the list of tiddler titles tagged with About and separated with pipe (|)!
<<dlist-link "[tag[About]]" " | ">>

produces

Acknowledgements | Contributors | History of TiddlyWiki | License | Releases | RoadMap

1 Like

Hi Mohammad,
Very interesting and useful macros. Thank you very much!

I think that the macro calls in case 2 / Testing should be dlist-link. In paragraph 2 you put a space before the hyphen, and in paragraph 3, you wrote dlist-list.

Could you please edit your own post? Just in case some users might copy-paste your solution without checking and wonder why it doesn’t work. Thanks!

Helpful! … So, Under the “no good deed goes unpunished” heading: :wink:

Could you see how to extend this logic so that a list-field column in your Shiraz dynamic tables could be made to display field contents in this delimited format? (I have many multi-word titles, and my current workaround is to alter stylesheet so that a.tc-tiddlylink has a bit of extra padding at left, so that I can easily see the gaps between listed items in dynamic table column in view mode. This would clearly be much better!)

1 Like

Springer
Do you mean a table column shows the list field as dlist-link format?
If I am correct, then yes, it is possible! You need to develop a column template! :wink:
Give a try and if you failed (you wont! :wink: ) then let me know to write one for you!