# Loop Until list is empty

Hi,

I am using Tiddlywiki for a while now and I am super happy with the functionality it offers to really build a big variety of use cases. Right now I am struggling with a problem, I am not really sure can easily be solved only with widgets and filters.

I want to build something like a tree structure of cause and error to certain failure mechanisms. Each tiddler represents such a failure and the immediate cause(s) is/are stored as a list in the according list-field.

So this structure can get very long and I want to be able to show a list of all the list entries as a chain, starting at a specific tiddler.

Is there an “easy” way to accomplish that?

You can use two list widgets:

<ul>
<$list filter="[has[causes]]"> <li><$link/>:
<ul>
<$list filter="[list[!!causes]]"> <li>{{!!title}}</li> </$list>
</ul>
</li>
</$list> </ul>  Example: Is that what you imagined ? What do you mean by “I want to start at a specific tiddler” ? How should the list be sorted ? 1 Like This sounds like a job for… macro recursion! Let’s assume you have a set of “failure” tiddlers, where each tiddler is tagged with “failure”, and has a field name causes, which contains a list of other failure tiddler titles. Something like this: • failure1: causes=“failure2” • failure2: causes=“failure3 failure4” (i.e., two different causes) • failure3: causes=“failure5” • failure4: causes=“failure6” • failure5: causes=“failure7” • failure6: causes=“failure7” • failure7: causes="" (blank field value or omit the field entirely) First, create a tiddler (e.g., “ShowCausesTemplate”), tagged with $:/tags/ViewTemplate, containing:

\define showCauses()
<$link/> <$list filter="[<currentTiddler>get[causes]enlist-input[]]">
<blockquote><$macrocall$name="showCauses"/></blockquote>
</$list> \end <$list filter="[<currentTiddler>tag[failure]]"><<showCauses>></$list>  Notes: • $:/tags/ViewTemplate causes the above wikitext content to be invoked for EVERY tiddler
• But the $list widget at the end of the tiddler checks to see if the current tiddler is tagged with failure, so that the <<showCauses>> macro is only processed for tiddlers that are actually ‘failure’ tiddlers. • Within the <<showCauses>> macro: • The $link widget shows the name of the current tiddler in the chain
• The $list widget loops through each “cause” listed in the current tiddler • <blockquote>...</blockquote> provides indentation for showing each step in the chain • The $macrocall does the recursion for each “cause”

The resulting output for tiddler “failure1” will look something like this:

failure1
| failure2
| | failure3
| | | failure5
| | | | failure7
| | failure4
| | | failure6
| | | | failure7


Hope this meets your needs… let me know how it goes.

enjoy,
-e

4 Likes

@EricShulman perfect, that´s the solution! Thank you very much!