Closed AnthonyMuscio closed 9 months ago
I think that this would be best implemented as a macro. We could make a javascript macro that has more complex internals, but just a simple wikitext macro may work.
\define if(condition than else)
<$list filter="""$condition$""" emptyMessage="""$else$""">$than$</$list>
\end
<<if "[go[yes]]" then:"""{{action-yes}}""" else:"""{{action-no}}""">>
the transclusions for action-yes and action-no are properly passed through as long as the quotes are there. And leaving off else works fine.
Jed
Nice work, to me it is however debatable that is best given the tripple ticks are a little more fragile.
I suppose people would like it if then else to be inline, but as soon as we move wikitext into macros or transclusions like in our examples, we are effectively modualarising the wikitext and these neat things can be done.
I wonder if there is more we could do to help this modularisation. For example using macros defined in the current tiddler however, allow such macro definitions to be placed anywhere in the tiddler as long as they are closed eg \define \end so they can be defined near where they are used.
Regards Tony
@AnthonyMuscio ... can this be solved, with the new ~
filter run? see: https://tiddlywiki.com/#Filter%20Expression
@AnthonyMuscio ... Is this issue still relevant. If not please close.
Closed due to "Conditional Shortcut Syntax" in the pre-release
As in the Google Discussion If-Clause in TW?
A current working example of if then else is in fact
Which made me think With a clone and minor re-write of the Listwidget we could have something like this;
<$if "[go[yes]]" then=<<action-yes>> else=<<action-no>>/> <!--THIS IS A FICTION-->
For filters resulting in more than one item there could be a implied limit[1] to make it true or false. You can see that "else is just emptyMessage", and "then" is just what would have being the content of the list widget.
Of course it would be handy if transclusions of tiddlers or fields where honoured, which I imagine is only a matter of wikifying the parameters of then and else
<$if "[go[yes]]" then={{action-yes}} else={{action-no}}/> <!--THIS IS A FICTION-->
or<$if "[go[yes]]" then={{!!action-yes-field}} else={{!!action-no-field}}/> <!--THIS IS A FICTION-->
Perhaps the resulting widget could be designed to use a shorter form of inline
<$if "[go[yes]]" then {{action-yes}} else {{action-no}} /> <!--THIS IS A FICTION-->
Where then and else are reserved words with a new line and else is optional
<$if "[go[yes]]" {{action-yes}} /> <!--THIS IS A FICTION-->
Where then is optional
Regards Tony