Having trouble filtering on variable named using $set filter=

hi folks. here’s one that’s got me perplexed

(run this in tiddlywiki.com)

<$set name="theTaggedTiddler" filter="[tag[HelloThere]nth[1]get[title]]">
theTaggedTiddler is <<theTaggedTiddler>><br>
why doesn't this work? 

<$list filter="[tag<theTaggedTiddler>]"/><br>```

What about </$set> ?

Even though the $set filter is returning only one title, that title contains spaces. As a result, the value contained in theTaggedTiddler is enclosed in doubled square brackets. Then, in your “diagnostic” output

theTaggedTiddler is <<theTaggedTiddler>><br>

the contents of theTaggedTiddler are being automatically rendered as a link so the doubled square brackets don’t appear.

To see what theTaggedTiddler variable actually contains, use:

theTaggedTiddler is <$text text=<<theTaggedTiddler>>/>

which is rendered as:

theTaggedTiddler is [[A Gentle Guide to TiddlyWiki]]

There are two ways to address this. You can either add a select=0 parameter to the $set widget to return the first result without the doubled-square brackets:

<$set name="theTaggedTiddler" filter="[tag[HelloThere]nth[1]get[title]]" select=0>

or, use a $let widget with a filtered transclusion, which automatically returns only the first result (again, without the doubled-square brackets):

<$let theTaggedTiddler={{{ [tag[HelloThere]nth[1]get[title]] }}}>

Also, note that get[title] is redundant in all of the above filters, as [tag[HelloThere]nth[1]] is already producing a tiddler title as it’s output. In addition, if you use a $let widget, then the nth[1] is also not needed, as $let automatically returns the first result.

Thus, the cleanest syntax to use is:

<$let theTaggedTiddler={{{ [tag[HelloThere]] }}}>

enjoy,
-e

Eric, thanks so much; that was exactly it.

I feel like I’ve made this mistake before, and you’ve guided me before on the same issue, but I couldn’t find it in the group; might have been in the google newsgroup days.

With the new functions this can be made much tidier;

\function the.TaggedTiddler() [tag[HelloThere]]

<<the.TaggedTiddler>>
  • Try the above on tiddlywiki.com
  • Functions by design return only the first title so no need for nth[1] or first[]
  • Functions return the result as text so they do not turn into links.
  • We could parametrize this to provide the tag name

I can explain more but this hints at the possibilities.

<$tiddler tiddler=<<the.TaggedTiddler>> >

everything acting on the selected tiddler here

</$tiddler>

Other things to know about functions;

\function full.list() [tag[HelloThere]] +[format:titlelist[]join[ ]]
\function list.string() [tag[HelloThere]] +[join[ ]]
  • full.list can be displayed or use enlist to divide back into a title list.
  • list. Sting creates a single string of all titles separated by spaces. You can’t enlist it back to the source.