Filter operators: THEN ELSE ~(ELSE)

66 views
Skip to first unread message

Mohammad

unread,
Dec 4, 2019, 9:51:20 AM12/4/19
to tiddl...@googlegroups.com
I am wondering how to use filter operator THEN, ELSE and ~(else)

Why the below fails

<$list filter="[<a>then<b>else<c>]>


</$list>


What is the difference between else and ~?

<$list filter="[<a>else<b>]">


</$list>


and 

<$list filter="[[<a>] ~[<b>]]">


</$list>


--Mohammad

Eric Shulman

unread,
Dec 4, 2019, 10:46:44 AM12/4/19
to TiddlyWiki
On Wednesday, December 4, 2019 at 6:51:20 AM UTC-8, Mohammad wrote:
I am wondering how to use filter operator THEN, ELSE and ~(else)
Why the below fails
<$list filter="[<a>then<b>else<c>]>

not sure.  gotta think about this a bit... 

What is the difference between else and ~?
<$list filter="[<a>else<b>]">
and 
<$list filter="[[<a>] ~[<b>]]">
 
The big difference here is that else[...] can only substitute a single value, while ~[...] can be a complex filter expression

-e

PMario

unread,
Dec 4, 2019, 10:49:18 AM12/4/19
to TiddlyWiki
Hi,

then and else are used in a filter run. ~ starts a new run.

See the docs list.

-m

TiddlyTweeter

unread,
Dec 4, 2019, 11:06:46 AM12/4/19
to TiddlyWiki
Could you give a concrete example? Just asking for a friend :-)

Mohammad

unread,
Dec 4, 2019, 2:20:42 PM12/4/19
to TiddlyWiki
Yes, I hope to see more example to see how they work!

--Mohammad

TonyM

unread,
Dec 4, 2019, 3:56:28 PM12/4/19
to TiddlyWiki
I think the best way for me is to think of then and else operators is they return a string, or title if the list is not empty then or else if list is empty.


Generate/list titles > then[hastitles]else[notitles]

So the above coded as a filter will only ever return hastitles or notitles.

The ~ on the other hand does test for empty list as well and can return a single title or new list.

Along with match these new operators will allow us to write filters more logically and in more natural language, I would say plain English like but the titles can be any language.

By being able to generate a string/title output on ones choosing from a filter, the wiki text can have further tests to respond to the generated result.

Happy to post examples as I collect them for myself.

Tony

TonyM

unread,
Dec 4, 2019, 4:11:33 PM12/4/19
to TiddlyWiki
You examples look wrong to me

[<a>then<b>else<c>]

Basicaly you are using three variables as titles and you are relying on an empty variable to be the same. In your example you are only testing for the existence of a and returning either b or c.

This may be what you want?

tony

Xavier Cazin

unread,
Dec 4, 2019, 4:56:57 PM12/4/19
to tiddl...@googlegroups.com
Hi Mohammad,

A good concrete example could be a followup to your recent template question. Here, we used the ~[...] construct to compute a tiddler title (or a list thereof):

<$list variable=template filter="[tag[a]] ~[tag[b]] ~[[tid3]]">
<$transclude mode=block tiddler=<<template>> />
</$list>

The computation of tid2 could have been of course arbitrarily more complex than [tag[b]].
If we wanted to use the else operator on the other hand, the only thing we could have done would have been to directly write tiddler titles that were previously known, like in:

<$list variable=template filter="[tag[a]else[tid2]else[tid3]]">
<$transclude mode=block tiddler=<<template>> />
</$list>

Or at most, got from a variable or a  field:

<$list variable=template filter="[tag[a]else<variable-holding-tid2>else{field-holding-tid3}]">
<$transclude mode=block tiddler=<<template>> />
</$list>

By the way, your test below is indeed intriguing. It looks like the operator title (hidden in the <a> expression) always constructs something that won't be considered empty by the rest of the filter, whatever the value of the variable <a> is. In other words, it always returns b. It sounds like a bug to me :-)

<$list filter="[<a>then<b>else<c>]">

</$list>


-- Xavier


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/8a4a3a6b-5050-416e-85f9-9f31bfb5b8c1%40googlegroups.com.

TonyM

unread,
Dec 4, 2019, 5:36:14 PM12/4/19
to TiddlyWiki
Mohammad et al,

Also consider the use of 

getvariable Operator

New in: 5.1.20 The usual way to retrieve a variable value within a filter is with the angle brackets notation. For example, [<currentTiddler>] will retrieve the value of the variable called currentTiddler.  

eg Untested by me just now

[<a>] or [<a>match[yes]] or [<a>else[novalue]]

Also

is Operator


New in: 5.1.20 is[variable]] test exists as a variable (whether or not that variable has a non-blank value)
blank
New in: 5.1.20 is[blank] (i.e. is a zero length string)

Tony
Reply all
Reply to author
Forward
0 new messages