This is an old feature request from GitHub[3]. I closed it recently! I share it here, may help for better solutions.
In Javascript, C, C++ we have a programming construct called Switch-Case
See : JS: JavaScript Switch Statement,
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
The below codes can do equivalent operation!
Case i
This is a simple solution and simple action can be used here.
\define switch(item, list:"a b c")
<$list filter="[enlist<__list__>search<__item__>]" emptyMessage="Default">
You passed <<currentTiddler>>
</$list>
\end
<<switch a>>
<<switch b>>
Case ii
This is a more sophisticated solution as it implements the code blocks through action macros
\define a() This is the action for a.
\define b() This is action for b.
\define c() This is action for c.
\define default() This is default action.
\define switch(item, list:"a b c")
<$list filter="[enlist<__list__>search<__item__>]" emptyMessage=<<default>> variable="actMacro">
<$macrocall $name=<<actMacro>> />
</$list>
\end
<<switch a>>
<<switch b>>
<<switch d>>
The request was to add <$switch>/<$case>
to simply do above operation. Decision making using switch/case is a very common in other programming languages. See [3].
Reference
[1] https://groups.google.com/d/msg/tiddlywiki/dZVMyjUUPoQ/ltpC41q3DAAJ
[2] https://groups.google.com/d/msg/tiddlywiki/dZVMyjUUPoQ/grjx3E7LDAAJ
[3] Feature request: "Switch Case Construct" · Issue #4064 · Jermolene/TiddlyWiki5 · GitHub