Clarification: How filter operator, :filter, and :map run prefixes work?

Saq,

So, the below shall give correct answer, but it does not:

\define mac(scope:"[tag[Filter Operators]]")
<$let
    letters  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    cond     = "$scope$ +[prefix<currentTiddler>]"
>

<$list filter="[<letters>split[]filter<cond>]">
<$text text=<<currentTiddler>> /> 
</$list>

</$let>
\end

<<mac>>

@twMat
Actually it will wrap into a macro and one need to be able to pass different scope!
See another example I have given above!

Excuse my stupid question: What can :map be used for?

As they say, Did you “RTFM” :wink:

Two issues that I see:

  1. Are there any filter operators starting with uppercase letters?
  2. You aren’t using a selection constructor inside the :filter run, start it with all[tiddlers] as by default it only gets a single title as input.

Some links to real world examples here on the forum:

1 Like

I tried with <<mac "[tag[Learning]]">> where there are output with uppercase, still no result!

I am not sure if I follow you! do you mean:

cond     = "[all[tiddlers]] +$scope$ +[prefix<currentTiddler>]"

I got the correct result if I go as below

\define mac(scope:"")
<$let
    letters  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		cond     = "[all[tiddlers]] +$scope$ +[prefix<currentTiddler>]"
>

<$list filter="[<letters>split[]filter<cond>]">
<$text text=<<currentTiddler>> /> 
</$list>

</$let>
\end

Note to the cond!

@saqimtiaz , is this the correct solution?

I have concluded this discussion in the original post (first post in this thread )
I appreciate if Saq (@saqimtiaz) kindly read and correct if there is any incorrect conclusion!
Any contribution is welcome! I also kindly ask Brian (@btheado) if kindly have a look and see if these are can be added to tiddlywiki.com documentation!

Looks correct to me.

1 Like

I think the only part that maybe needs to be made more explicit in the docs is that :filter, :map and :reduce only receive a single title as input. So if you want to query all tiddlers, you need to start your filter run with all[tiddlers].

1 Like

I added this to conclusion!

To see if I can contribute helpfully to this discussion, and to further my own understanding, I went back to the documentation, I think it fair to call it “Terse” or “sparing in the use of words”. As I come to understand this better I will need to find my own words to describe them, hopefully I can produce something that will help others. The descriptions reads to me as exactly what someone who already understands it would write, not what something someone who does not understand it needs to read.

Starting with referring to filter filter1 and filter2 would be a good start.

The value of currentTiddler outside the run is available in the variable “…currentTiddler”.

Can anyone show how to use <<..currentTiddler>> "outside the run?

[Edit] Also note https://tiddlywiki.com/#Filter%20Run makes no mention that “Filter Runs can have prefixes” and “Filter Run Prefix” tiddlers also make no mention of ## Filter Expression
which documents other prefixes = + - ~

Example demo

To show the application of this discussion, see the Simple Pagination Two example below.
It accept a filter (with any complexity) and produces a list with a header contains alphabetical index buttons! On click the output will be limited to titles prefixed with that letter.

Code

\define simple-pagination-two(scope:"[all[tiddlers]!is[system]]")
<$let
    letters      = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    cond         = "[all[tiddlers]] +$scope$ +[uppercase[]prefix<currentTiddler>]"
    tempTid      = "$:/temp/pagination"
    titlePrefix  = {{{ [<tempTid>get[text]] }}}
    listfilter   = "[uppercase[]prefix<titlePrefix>]"
    selStyle     = "[<currentTiddler>match<titlePrefix>then[font-weight:bold;color:red;]]"
>

<!-- create header -->
<$list filter="[<letters>split[]filter<cond>]">
<$button style="color:navy;margin:1px;width:2em;height:1.8em;cursor:pointer;">
<span style={{{[subfilter<selStyle>]}}} ><$text text=<<currentTiddler>> /></span>
<$action-setfield $tiddler=<<tempTid>> text=<<currentTiddler>> />
</$button>
</$list>

<!-- generate output -->
<$list 
  filter="[subfilter<__scope__>filter<listfilter>sort[title]]"
  template="$:/core/ui/ListItemTemplate" 
/>
</$let>
\end

To give a try

Remarks

  • Two filter operator is used, cond and listfilter
  • Note to the usecases in
    • filter="[<letters>split[]filter<cond>]"> and
    • filter="[subfilter<__scope__>filter<listfilter>sort[title]]"
  • Some css styles have been used as cosmetic!

Screencast

In the below an example the macro is called with

<<simple-pagination-two "[tag[Filter Operators]] [tag[Filter Run Prefix]]">>

which produces

img_842_msedge

2 Likes

Hi @Mohammad, just wanted to add my two cents regarding the :filter[] run prefix.

Although there are currently no examples in the doc that shows such construction, one can use filter variables with run prefixes.

Only, we must use the subfilter operator in order to load the subfilter (as usual in fact). For instance, one could modifly you last demo example from:

<!-- generate output -->
<$list 
  filter="[subfilter<__scope__>filter<listfilter>sort[title]]"
  template="$:/core/ui/ListItemTemplate" 
/>

to:

<!-- generate output -->
<$list 
  filter="[subfilter<__scope__>] :filter[subfilter<listfilter>] +[sort[title]]"
  template="$:/core/ui/ListItemTemplate" 
/>
2 Likes

Hi Xavier,
Lovely! Many thanks for your input!

Does this violate conclusion 5 above?

No, the :filter filter run itself cannot be a variable. However just like any other filter run you can use variables inside it.

Thank you Saq, so I leave conclusion 5 intact! I appreciate to correct me if I misunderstood any part, then I will revise the conclusion above!

Hello @Mohammad,
I would like to have in the output also my user field ‘erstellt’ like
grafik

How can this be done (with CSS style)?

Thanks in advance!
Stefan