On Wednesday, October 14, 2020 at 2:09:57 AM UTC-7, Jean-Pierre Rivière 
wrote:
>
> \define countTaggedBySelf() <$count 
> filter="[all[current]tagging[]butfirst[]]"/>
> <$set name="qty" value=<<countTaggedBySelf>> >
> <$set name="loc" 
> filter="[<qty>compare:number:gt[1]then[several]else[single]]">
> got <<qty>>: <<loc>><br/>
> </$set></$set>
>
> Then I get "got 2: single" ??? (in a tiddler where the countTaggedBySelf 
> has sense and returns 2.)
> But if I write instead
> <$set name="qty" value=2 >
>

Macros do *not* "evaluate the syntax and return the output"... they just do 
substitutions for $param$ and $(variable)$

Thus, countTaggedBySelf() does not return a number, it returns: <$count 
filter="[all[current]tagging[]butfirst[]]"/>
and the subsequent <$set name="qty" ...> also just sets the qty variable 
to: <$count filter="[all[current]tagging[]butfirst[]]"/>

There are several ways to fix this:

Method #1: use <$wikify> to convert the <$count> into it's actual number:
\define countTaggedBySelf() <$count filter=
"[all[current]tagging[]butfirst[]]"/>
<$wikify name="qty" text=<<countTaggedBySelf>> >
<$set name="loc" filter=
"[<qty>compare:number:gt[1]then[several]else[single]]">
got <<qty>>: <<loc>><br/>
</$set></$wikify>

Method #2: use the [count[]] filter instead of the $count widget:
<$set name="qty" filter="[all[current]tagging[]butfirst[]count[]]" >
<$set name="loc" filter="[<qty>
compare:number:gt[1]then[several]else[single]]">
got <<qty>>: <<loc>><br/>
</$set></$set>

Simplification #1: if you don't need the "qty" value, combine all the 
filter syntax
<$set name="loc" 
filter="[all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]]">
got <<loc>><br/>
</$set>

Simplification #2: use $vars with a "filtered transclusion" instead of $set
<$vars loc={{{ 
[all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]]
 
}}}>
got <<loc>><br/>
</$vars>

Simplification #3: if you just want to display the result, skip the $vars 
(or $set) entirely:
{{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]
else[single]] }}}

enjoy,
-e




-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/6f0a8fcd-ebe8-49a8-a5d6-a6d22fabf5e0o%40googlegroups.com.

Reply via email to