IF CONDITION THEN TRUE-PARTELSE FALSE-PARTEND IF\define _maca(x) This is Macro ''A'': $x$\define _macb(y) This is Macro ''B'': $y$
\define polymorph(input, cond:"a") <$reveal type="match" text=$cond$ default="a")> <<_maca $input$>> </$reveal> <$reveal type="match" text=$cond$ default="b")> <<_macb $input$>> </$reveal>\end
<<polymorph "Hi">><<polymorph input:"Hello">><<polymorph input:"Hola" "b">><<polymorph input:"Hola" cond:"b">>This is Macro A: Hi
This is Macro A: Hello
This is Macro B: Hola
This is Macro B: Hola
IF CONDITION THEN TRUE-PARTELSE IF OTHER-PARTELSE FALSE-PART END IFEven using the emptyMessage in list and emptyVale in set widgets helps.
You can nest list widgets in any combination you want. I have half written a guide on this, tw equivalents to normal code structures, I can share the draft.
It takes a little to learn the filter equivalent of if tests but once mastered they can be more powerful because they are not only logical operators but act on sets of titles (which can be litteral values not just tiddler titles).
One difference is tw does not favor simple true false test as much because what it offers is designed to respond to tiddlers, tags and fields and is thus much richer.
Providing some simpler tests may assist users.
Regards
Tony
[prefix[tiddlername]suffix[tiddlername]] is both its prefix and its suffix
<$list filter="filter1">
Do this for each filter1 case
<$list filter="filter2">
Do this for each filter2 case
<$list filter="filter3">
Do this for each filter3 case
<$list filter="filter4">
Do this for each filter4 case
</$list>
</$list>
</$list>
</$list><$list filter="yourfilter">
Do this for each case
</$list><$list filter="yourfilter">
Do this for each case
<$list filter="specificcase1filter">
Do this for each specificcase
</$list>
<$list filter="specificcase2filter">
Do this for each specificcase2
</$list>
</$list>
Hi Tony,
I figured this might be of interest for your collection, there is another way to do conditionals within certain limits if one has the "Tinka" plugin installed. Specifically, it includes a plugin similiar to the reveal widget in its function but also allows you to check for regex expressions. An example use (taken straight from the error-checking section of Tinka):
<!-- Check whether a plugin title was given -->
<$tinka-check text={{!!create-title-org}} pattern="^[^\s]+$">
<$tinka-filter verb="fail">
<$action-setfield $tiddler=<<TinkaVars>> result="true"/>
<$action-setfield $tiddler=<<TinkaVars>> errorTitle="The plugin title is not allowed to be empty or contain whitespaces."/>
</$tinka-filter>
<$tinka-filter verb="pass">
<!-- Do something else, plugin title is valid. -->
</$tinka-filter>
</$tinka-check>
This is entirely undocumented, but I think its a neat way to do a conditional entirely with action widgets (all of those are). Note that "pattern" could also just be a value of another tiddler field, in which case the verbs "pass" and "fail" would correspond to "match" and "nomatch" for the reveal widget. It does only work for action widgets though, since nothing is rendered.
/Andreas
<$list filter="[enlist<hascaption>prefix[true]]" variable="null">
Has caption
</$list>
So in this case we use a "textual" description of the condition we are testing eg; hascaption
RegardsTonyWhat do you think if use the left bar for table of contents?
There are some stuffs prepared by others like Tobias Beer, Jed carty, Dave Graford, what do you think if you merge part of them here, those part are useful?
Is it possible to invite others to help and have a community to prepare, edit and review the contents?
Hello Andreas