Thank you Eric. Once again, I stumble upon the terrible rule "macro do only 
text substitution". I know it, but I have not yet realized all what it 
means. I selectred the wikify approach of method #1 as I want to keep using 
the countTaggedBySelf macro to avoid duplicating code.

Simplification #3 creates a link, which is not wanted. Is there a similar 
quick notation to just get the raw text instead of an internal link? Note 
that is whay I created my macro with the count widget inside.

Regards,

Le mercredi 14 octobre 2020 à 11:55:03 UTC+2, Eric Shulman a écrit :

> 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/5560aad2-6fd9-4626-a777-40b7690486fbn%40googlegroups.com.

Reply via email to