Question: a comparison filter more like a switch-case

35 views
Skip to first unread message

Mohammad Rahmani

unread,
Feb 14, 2021, 11:59:18 PM2/14/21
to tiddl...@googlegroups.com
I want to return a color based on the user input: x

x <= -5   color:red
x < 0     color:yellow
x = 0     color:grey
x > 0     color:blue
x >= 5    color:green

As a test, I have implemented the below solution.

<$vars x=-3><!-- change x here -->
<$list filter="[<x>compare:number:lt[0]then[yellow]] [<x>compare:number:lteq[-5]then[red]] [<x>compare:number:gt[0]then[blue]] [<x>compare:number:gteq[5]then[green]] +[last[]]" emptyMessage=grey>
<<currentTiddler>>
</$list>
</$vars>


Copy paste in an empty tiddler in https://tiddlywiki.com/ and change x and see the result, it works fine, but seems a lengthy solution.
What simpler, more semantic alternative do you propose?


Best wishes
Mohammad
Reply all
Reply to author
Forward
0 new messages