A simple example: In a list I want to display each entry with a dedicated color, so when I iterate on a list items I need to read colors from an array like color(1), color(n)
I know I can add a field to each tiddler and set colors or use a data dictionary with 1:red, 2:yellow, …
But I am looking for a dynamic way as I can use in scripts!
It’s an interesting question. I had to do something similar recently:
\define colours() red green blue orange
<$let numberOfColours={{{ [<colours>enlist-input[]count[]] }}}>
<$list filter="[all[tiddlers]sort[]]" counter="counter">
<$let colourIndex={{{ [<counter>subtract[1]remainder<numberOfColours>add[1]] }}}>
<div style={{{ [<colours>enlist-input[]nth<colourIndex>addprefix[color:]addsuffix[;]] }}}>
<$text text=<<currentTiddler>>/>
</div>
</$let>
</$list>
</$let>
Output:
<div style="color:red;">
"A free, open source wiki revisited" by Mark Gibbs, NetworkWorld
</div>
<div style="color:green;">
"A Thesis Notebook" by Alberto Molina
</div>
<div style="color:blue;">
"ATWiki" by Lamusia Project
</div>
<div style="color:orange;">
"BJTools" by buggyj
</div>
<div style="color:red;">
"BrainTest - tools for a digital brain" by Danielo Rodriguez
</div>
...
I would just add that in my view, many things can be considered an array in tiddlywiki a list of titles can be accessed via an index with the set widget, and filters can be used to manipulate, select, count entries in almost any list, so in some ways arrays are everywhere but nowhere. The list field used by tags or even each row in a text field are similar. And now with the new widgets that use the $fields and $values parameters such as