The new filter prefix ELSE (~)

109 views
Skip to first unread message

Mohammad

unread,
Nov 21, 2018, 11:50:44 PM11/21/18
to TiddlyWiki
The new prerelease 5.1.18 has introduced a new filter prefix called Else

See below:


  •  NEW IN: 5.1.18 the prefix ~, if the filter output so far is an empty list then the output titles of the run are dominantly appended to the filter's output. If the filter output so far is not an empty list then the run is ignored

In technical / logical terms:

RunInterpretationOutput
rununion of sets... OR run
+runintersection of sets... AND run
-rundifference of sets... AND NOT run
~runelse... ELSE run


Has anybody tried it? I appreciate to share some examples here

Cheers
Mohammad

TonyM

unread,
Nov 22, 2018, 1:47:48 AM11/22/18
to TiddlyWiki
Mohammad,

I believe it just came out, so I doubt many have.

On the git hub item I asked if multiple can be strung together, something I will test soon.

I just tried this to display the caption and if none the tiddler name
<<currentTiddler>>
<$set name=display-title filter="[all[current]get[caption]] ~[{!!title}]">
<
<display-title>>
<$link to=<
<currentTiddler>> tooltip="Open tiddler"><<display-title>></$link>
</$set>

However the link opens the non existent tiddler with the caption name rather than <<currentTiddler>>

Not sure why that would be

Regards
Tony

Riz

unread,
Nov 22, 2018, 2:21:26 AM11/22/18
to TiddlyWiki
Hi Tony,

It worked as expected for me when I tested in tiddlywiki-prerelease page.

sincerely
Riz

TonyM

unread,
Nov 22, 2018, 2:34:11 AM11/22/18
to TiddlyWiki
Some experiments,

The Following gets the value from test, if empty test2 if empty test3

<$list filter="[all[current]get[test]] ~[all[current]get[test2]] ~[all[current]get[test3]]">

</$list>

In this case you will never get the emptyMessage only emptyval returned as a title
<$list filter="[all[current]get[test]] ~[all[current]get[test2]] ~[all[current]get[test3]] ~[[emptyval]]" emptyMessage="Empty">

</$list>

The following gets the value of test if it has one, otherwise returns testempty
<$list filter="[all[current]get[test]] ~[[testempty]]">

</$list>
Not really different to emptyMessage

I have not worked out how yet, but I am convinced we can do some very complex conditionals using + - and ~

This will tell us a tiddler is "not active" if it has an item-completed or item-cancelled field with contents

<$list filter="[all[current]has[item-cancelled]] ~[all[current]has[item-completed]]">
Not active
</$list>

Regards
Tony

Mohammad

unread,
Nov 22, 2018, 3:41:55 AM11/22/18
to TiddlyWiki
Thank you Tony!

Let's try your examples. I hope Jeremy adds some examples!


Cheers
Mohammad

Jeremy Ruston

unread,
Nov 24, 2018, 5:52:53 AM11/24/18
to tiddl...@googlegroups.com
Hi Tony, Mohammad,

A couple of points about this example:


On 22 Nov 2018, at 06:47, TonyM <anthony...@gmail.com> wrote:

<<currentTiddler>>
<$set name=display-title filter="[all[current]get[caption]] ~[{!!title}]">
<
<display-title>>
<$link to=<
<currentTiddler>> tooltip="Open tiddler"><<display-title>></$link>
</$set>


First, you’re displaying the name of the current tiddler using a macro invocation <<currentTiddler>>. The problem there is that the text will be wikified, so if you have a tiddler called “This //is// my tiddler” then the title will not be displayed as expected. To avoid wikification you can use <$text text=<<currentTiddler>>/>.

Second, you’re evaluating the filter using the “filter” attribute of the set widget. The action of the set widget here is to evaluate the filter, and then store all of the results in the target variable as a list (ie, space separate tiddler titles, with double square brackets for quoting titles that contain spaces).

That means that if your caption contained, say, “This is the caption”, then the text that would be assigned to the variable display-title would be “[[This is the caption]]” (ie including the double square brackets).

You’re probably better off using the filtered transcluded attribute syntax:

<$set name=display-title value={{{ [all[current]get[caption]] ~[{!!title}] }}}>

Using the triple braces the quote an attribute value causes the string within the quotes to be evaluated as a filter, and then the first entry (if any) is returned. Thus, with the example above you’d get the expected text “This is the caption”, without the double square brackets.

Best wishes

Jeremy

Mohammad

unread,
Nov 24, 2018, 9:17:20 AM11/24/18
to TiddlyWiki
Thank you Jeremy!
I appreciate to give us some practical examples of using the filter prefix ELSE(~).

Best
Mohammad

TonyM

unread,
Nov 24, 2018, 7:29:28 PM11/24/18
to TiddlyWiki
Thanks Jeremy,

I will drink this advice deeply, and take more care with my understanding when a result is wikified or not.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages