Struggling with viewtemplate filter

97 views
Skip to first unread message

Dave Parker

unread,
May 1, 2020, 1:24:19 PM5/1/20
to tiddl...@googlegroups.com
There's something fundamental about filters that I'm not getting:

in the advanced search filter tester thingie, this works:

EXAMPLE 1: 
[is[current]][tag[Subjective]]-[!regexp:dates[2020-05-01]]

i.e. it lists the single tiddler with the correct dates field


but in a viewtemplate tiddler:

EXAMPLE 2: 
<$set name="mytoday" value="{{my-now}}">
<$list filter="[is[current]][tag[Subjective]]-[!regexp:dates[2020-05-01]]" variable=null>
                             
{{||SubjectiveTemplate}}
</$list></$set>

it doesn't work


this does work (carets not really in code, just to point out the difference):

EXAMPLE 3: 
<$set name="mytoday" value="{{my-now}}">
<$list filter="[is[current]]-[!tag[Subjective]]-[!regexp:dates[2020-05-01]]" variable=null>
                            ^ ^
{{||SubjectiveTemplate}}
</$list></$set>




but this doesn't work:

EXAMPLE 4: 
<$set name="mytoday" value="{{my-now}}">
<$list filter="[is[current]]-[!tag[Subjective]]-[!regexp:dates[<
<mytoday>>]]" variable=null>
                                                                    ^
{{||SubjectiveTemplate}}
</$list></$set>

all tiddlers are rendered as a match


and neither does this:

EXAMPLE 5: 
<$set name="mytoday" value="{{my-now}}">
<$list filter="[is[current]]-[!tag[Subjective]]-[!regexp:dates<
<mytoday>>]" variable=null>
                                                              ^
{{||SubjectiveTemplate}}
</$list></$set>

no tiddlers are rendered as a match


Just wondering 2 things:
A) why does EXAMPLE 1 work but not 2? (or why 3 and not 2)
B) Although using <<mytoday>> outside of the filter does return the correct date, why does it not work inside the filter?


Thanks,
- Dave

Mark S.

unread,
May 1, 2020, 1:55:58 PM5/1/20
to TiddlyWiki
You say "doesn't work" without explaining what you mean. Is there no output? The wrong output? These details are essential to understanding what's happening.

You might start by a clear statement of what you want your template to look for.

In any event, this:

[is[current]][tag[Subjective]]

should probably be this:

[is[current]tag[Subjective]]

In the first one you're listing everything that is current (the current tiddler) AND everything tagged with "Subjective". That's probably not what you meant. In the second one, you're using the template on the current tiddler IF it is tagged with "Subjective". It seems like you also want to prevent the template from being used if the dates field does not match 2020-05-01.

I think what you want is:

[is[current]tag[Subjective]regexp:dates[2020-05-01]]

In example 2, you do this:

<$set name="mytoday" value="{{my-now}}">

But variable "mytoday" never gets used that I can see. In any event, it should probably be

  <$set name="mytoday" value={{my-now}}>

The value "{{my-now}}" will give you the literal string "{{my-now}}"

HTH

Dave Parker

unread,
May 1, 2020, 2:43:20 PM5/1/20
to TiddlyWiki
Ok, I think I need to start over with the filters tutorials, but given what you've said so far and given [[headache]] with field "dates"=2020-05-01 and [[neck pain]] with field "dates"=2020-04-23 <-- i.e. not today


[tag[Subjective]regexp:dates[2020-05-01]] <-- in the advanced filter thingie does list "headaches" only (correct)

Now, when I do this in a viewtemplate
<$list filter="[tag[Subjective]regexp:dates[2020-05-01]]" variable=null>


                             
{{||SubjectiveTemplate}}
</$list>



it brings up the SubjectiveTemplate in *ALL* tiddlers.  Why would that happen?

Mark S.

unread,
May 1, 2020, 3:55:51 PM5/1/20
to TiddlyWiki
You forgot "[is[current]..." at the start. Without that, it will find everything tagged with Subjective, etc.

Dave Parker

unread,
May 1, 2020, 5:05:33 PM5/1/20
to TiddlyWiki
Thanks, I'll try that when I get home, but in the mean time, why don't you need that in the advanced search filter?

(That's one of those things I don't really understand and just (sometimes) paste it into filters, crossing fingers)

Mat

unread,
May 1, 2020, 5:19:26 PM5/1/20
to TiddlyWiki
Dave Parker wrote:
why don't you need that in the advanced search filter?

"is[current]" is the same as <currentTiddler>, i.e it means that the filtering should only concern the current tiddler.

...and actually, there was some analysis made a while back that concluded it is actually faster/more efficient to use

all[current]

so make it a habit to use this operator instead of "is", (even if the statement "all current" sounds corny per se)

<:-) 

Dave Parker

unread,
May 1, 2020, 8:32:32 PM5/1/20
to TiddlyWiki
"You forgot "[is[current]..." at the start. Without that, it will find everything tagged with Subjective"

- isn't that what I want?  I thought filters were like a pipe, so this
<$list filter="[tag[Subjective]regexp:dates[2020-05-01]]" variable=null>

would mean that you list all tiddlers with the tag "Subjective", and from that list you filter out everything *but* those with a dates field that contains "2020-05-01"


So leaving that aside, if i have this corrected viewtemplate:
<$set name="mytoday" value={{my-now}}>
<$list filter="[all[current]tag[Subjective]regexp:dates[2020-05-01]]" variable=null>

<<mytoday>>
</$list></$set>

which puts today's date at the bottom of only tiddlers with the tag "Subjective" and the dates field containing "2020-05-01"

So far so good.


but when I replace 2020-05-01 with <<mytoday>>, like this
<$set name="mytoday" value={{my-now}}> <$list filter="[all[current]tag[Subjective]regexp:dates[<<mytoday>>]]" variable=null>

<<mytoday>> </$list></$set>

 or this
<$set name="mytoday" value={{my-now}}> <$list filter="[all[current]tag[Subjective]regexp:dates<<mytoday>>]" variable=null>

<<mytoday>> </$list></$set>


I get nothing...  I also tried replacing the word "set" with the word "wikify" and that didn't work either.

Any further suggestions?  Maybe I need to put this in a macro and use macrocall (that seems to be the answer to so many of these situations) - I'll try that and post back if it works





Mat

unread,
May 1, 2020, 8:40:52 PM5/1/20
to TiddlyWiki
The syntax is

...regexp:dates<mytoday>]" ...

Think like this: "I need the minimum to enclose it." (I'd think this is a decent rule of thumb but haven't considered it before.)

<:-)

Dave Parker

unread,
May 1, 2020, 8:45:26 PM5/1/20
to TiddlyWiki
Yes! we have a winner!

here's what worked:
\define subj2(mytoday)
<$list filter="[all[current]tag[Subjective]regexp:dates[$mytoday$]]" variable=null>

{{||SubjectiveTemplate}}
</$list>
\end

\define subj()
<$macrocall $name="subj2" mytoday={{my-now}} />
\end
<<subj>>

Thank you Mark and Mat for your prodding, that helped :)
 

Dave Parker

unread,
May 1, 2020, 8:50:00 PM5/1/20
to TiddlyWiki
"I need the minimum to enclose it."


So its kind of like, when its just raw text like dates[2020-05-01] you need the brackets to enclose that little phrase, but when you have a "formulaic" thing like dates<<today>>, because the << acts as a bracket of sorts, it can also double as the "enclosing" brackets

Dave Parker

unread,
May 1, 2020, 8:52:21 PM5/1/20
to TiddlyWiki
oh, maybe not: when I take the [ and ] from my final working example (thinking that maybe the $s would act as brackets) that broke it again.

Mark S.

unread,
May 1, 2020, 9:20:28 PM5/1/20
to TiddlyWiki
The "minimum" thing doesn't work with substitution variables (the ones with dollar signs $$). But this syntax should:

[all current]tag[Subjective]regexp:dates<__mytoday__>]

Why? Because! That's why. ;-)

Mat

unread,
May 2, 2020, 5:53:22 AM5/2/20
to TiddlyWiki
[[all current]tag[Subjective]regexp:dates<__mytoday__>]
 
<:-)
Reply all
Reply to author
Forward
0 new messages