Filter problem - unexpected result

Hi,

I’ve been trying to use a separate tiddler (‘Filters’) with the fields containing a series of filters which I can reference elsewhere.

In this example, Filters!!test =[tag[A]]

I noticed that for the list of tiddlers tagged with ‘A’,

\define custom() [filter{Filters!!test}]

<$vars X={{{ [filter<custom>]+[count[]]  }}}>  

{{{ [<X>] }}}

‘X’ will give the correct number of tiddlers:

but Y will only show the first entry in the list:

<$vars Y={{{ [filter<custom>]  }}}>  

{{{ [<Y>] }}}

Hope that makes sense.

What am I doing wrong?

Thanks
Jon

You’ve discovered the defining trait of filtered attribute values! When you use a filtered transclusion to define a variable, the variable is set to the value of the first result only.

  • In case X, since the filter output is a single number, {{{ [<X>] }}} = {{{ [filter<custom>] +[count[]] }}}
  • In case Y, since the filter output is a list of titles, {{{ [<Y>] }}}{{{ [filter<custom>] }}}

To save a list of more than one string as a variable, you’ll need to add +[format:titlelist[]join[ ]] to the end of the filter to turn it into a single string (spaces included), e.g.

<$vars Y={{{ [filter<custom>] +[format:titlelist[]join[ ]] }}}>

Then, to retrieve the list, use {{{ [enlist<Y>] }}}.

1 Like

That’s great - especially now I can think I discovered something!

Many thanks
Jon

Note that there are three different widgets that can be used to assign a value to a variable:

  • $set is the “original” widget for performing variable assignments.
  • $vars was added to provide a more compact syntax that can also assign multiple variables in the same widget.
  • $let was added to enable assignments where variables can depend upon previous assignments performed in the same widget.

For your specific use-case, instead of writing

<$vars Y={{{ [filter<custom>] +[format:titlelist[]join[ ]] }}}>

you can use

<$set name="Y" filter=<<custom>> >

The "$set with filter param" syntax automatically encloses values that contain spaces inside doubled square brackets (equivalent to the format:titlelist[] operator), and also automatically joins the values into a single space-separated list (equivalent to the join[] operator).

Also note that, while $vars is a valid widget, it has been superseded by the $let widget (introduced in v5.2.1):

references:
https://tiddlywiki.com/#SetWidget
https://tiddlywiki.com/#VarsWidget
https://tiddlywiki.com/#LetWidget

enjoy,
-e

4 Likes

Thanks Eric for the further information - that’s really useful.
Regards
Jon.

<$list filter=<<custom>>><$view field="title"/><br/></$list>