SetWidget - access filter output in value/emptyValue?

86 views
Skip to first unread message

Mat

unread,
Jun 21, 2017, 7:04:48 AM6/21/17
to TiddlyWiki


<$set name=foo filter="[prefix[New]count[]]" value="There are $filteroutput$ tiddlers with prefix New" >
<
<foo>>
</$set>

Because SetWidget filters are evaluated I'm guessing there must be variable with the filter result existing somewhere (in the js).

Is there some way to access this variable so that it can be used in the value parameter? (Here examplified with the $filteroutput$)

This would make it very easy to use the SetWidget as an "IF-then" statement or, if also using emptyValue, an "IF-then-else". Extremely useful.

For example

<$set name=foo filter="..." value=<<macro1>> emptyValue=<<macro2>> >

...where the macros thus can use the filter result, and you then access the final result via <<foo>>

<:-)

Mark S.

unread,
Jun 21, 2017, 10:04:48 AM6/21/17
to TiddlyWiki
Hi Mat,

The example you picked is problematic to start, because the count operator will always generate some output (zero is an output).

What you're trying to do is concatenate variables into a string. Whenever that happens, AFAIK, you need to use a macro.

You can use <$list> operators kind of to get the if-then thing. You can also use the reveal widget if your comparison value is already in a field or tiddler.

It would be great if there was a way to do comparisons like that in one swoop. Maybe someone will post one, but here's what I came up with:

\define foo() There are $(filteroutput)$ tiddlers with prefix New

<$list filter="[prefix[New]limit[1]]" emptyMessage="There are no tiddlers with prefix New" >
<$set name=filteroutput filter="[prefix[New]count[]]" >
<<foo>>
</$set>

</
$list>



Good luck,
Mark

Mat

unread,
Jun 21, 2017, 3:51:04 PM6/21/17
to TiddlyWiki
Thanks Mark, but I'm afraid I phrased my question too vaguely. I only posted the particular filter etc as an example. What I'm really wondering is really if I can somehow access the (i.e any) filter result in the SetWidget value/emptyValue attributes - or, perhaps, if it would make sense to post a feature request for this.

I.e does my suggestion make sense; that the filter result is stored in a variable somewhere in the js code and that it therefore should be at least pretty easy to modify the js code so that value/emptyValue can access it? It seems like a low hanging fruit but maybe I'm misunderstanding something?

Again, sorry for phrasing my question poorly and thanks for your kind reply Mark.

<:-)

Mark S.

unread,
Jun 21, 2017, 4:34:54 PM6/21/17
to TiddlyWiki
Why do you want the result in js? Are you writing a javascript macro? If so there's a function called "getVariable" that can get current variables for you. See
$:/core/modules/macros/changecount.js for an example of usage.

I don't think it's possible to insert the resulting value inside of the same <$set> because

1. You can't concatenate text that way
2. The variable isn't available until after the filter has 'run'

but I would love to learn if I was wrong.

I could see making a request for an additional <$set> output option, e.g. 'format="the count was %s"'

Good luck!
Mark

Mat

unread,
Jun 21, 2017, 5:31:39 PM6/21/17
to TiddlyWiki
Sorry again; I don't want the result *in* js (because I don't know js). I'm just guessing it should be "simple" to apply the resulting filter output value to the emptyValue/value variables in a similar way that is it applied to the name variable. I guess the name variable gets directly set with the value of the filter output, whereas something like this;

emptyValue="the filter result is %"

...would require first snooping up the % character and then replace it.


2. The variable isn't available until after the filter has 'run'

Yes, but the filter has always been run before either of the output variants are relevant... so my point is just that it might be possible to access this filter result in the output.


I could see making a request for an additional <$set> output option, e.g. 'format="the count was %s"' 

 What do you mean with "format"? How would it differ from using "value".


<:-)

Mark S.

unread,
Jun 21, 2017, 5:54:19 PM6/21/17
to TiddlyWiki


On Wednesday, June 21, 2017 at 2:31:39 PM UTC-7, Mat wrote:

2. The variable isn't available until after the filter has 'run'

Yes, but the filter has always been run before either of the output variants are relevant... so my point is just that it might be possible to access this filter result in the output.


I don't think it's available to other macros or widgets until it's completed. But it would be interesting to find out otherwise.

 
I could see making a request for an additional <$set> output option, e.g. 'format="the count was %s"' 

 What do you mean with "format"? How would it differ from using "value".

The %s would be substituted in situ. Currently the only way to do this is to call a separate macro to perform the concatenation.

Actually, I think that's what you wanted in your original post (you just used a different variable name).  You could certainly put in a request for it. I suspect it would take a substantial rewrite of the <$set> code, but who knows ...
 
Have fun,
Mark


<:-)
Reply all
Reply to author
Forward
0 new messages