Can Not Get Variable to Work in a Filter

I’m unable to figure out how to use a variable in a filter. The title of an existing tiddler I’m using is a tag as well. The tiddler title is Primary Bedroom. I have several other tiddlers tagged with Primary Bedroom.

Within the Primary Bedroom tiddler I have typed this.

<<list-links filter:"[tag[<currentTiddler>]]">>

My expectation is to see a list of tiddlers which are tagged Primary Bedroom. I get nothing.

This works

<<list-links filter:"[tag[Primary Bedroom]]">>

This does not work
<<list-links filter:"[tag[<currentTiddler>]]">>

This also doesn’t work
<<list-links filter:"[tag[<<currentTiddler>>]]">>

I’m obviously doing something wrong or I’m not understanding how to use variables. What should the syntax be?

OS = Windows 11
Browser = FireFox
Tiddlywiki Version = 5.2.5

You have too many brackets. Try this instead:

<<list-links filter:"[tag<currentTiddler>]">>

In filter syntax, square brackets don’t just indicate the parameter of the filter operator, they indicate a literal text value—like “Primary Bedroom”. [tag[<currentTiddler>]] would thus indicate all tiddlers with the tag “<currentTiddler>”, not the value of the <<currentTiddler>> variable.

Within a filter run, all brackets that are normally doubled in wikitext are used singly:

  • Literal strings: [[Primary Bedroom]] becomes [Primary Bedroom]
  • Variables: <<currentTiddler>> becomes <currentTiddler>
  • Transcluded values: {{Primary Bedroom}} becomes {Primary Bedroom}; {{!!list}} becomes {!!list}
2 Likes

etardiff,
Brilliant! Thank you so much. I’m still trying to understand single and double square brackets, angle brackets, and curly brackets. It’s all still swimming around in my head. Thank you again for responding and setting me straight. Cheers!

If it helps, what helped me is learning about this, is in our tiddlers we can have <<macros>> <hr><br> which is variables, html and widgets <$widgetname/>.

When it comes to variables/macros/procedures we need to be able to tell them apart from each other <htmltag> <$widget/> <<variable>>. However HTML and widgets are not permitted in filters, so we only need <varname> single < > to represent variables inside a filter.

Also consider [<currentTiddler>] vs <currentTiddler>

  • The first defines a “filter run” and a single title, containing only a variable, the second only the reference to the variable.
  • Consider your initial example [tag[<currentTiddler>]], its not valid to give a filter run as the parameter to the tag operator, only a variable.
    • In another way to think about this is <varname> delimits the name, you dont need additional delimiters if you are giving a variable, it has its own delimiters.
    • If instead you used a literal tag name [tag[tag name]] you need the [ ] to delimit the beginning and end of the literal parameter, but not here [tag<varname>]
1 Like

This is very educational/helpful. Thank you for laying this out in the fashion you did. Greatly appreciate it!

Here’s a tip for how to get the filter syntax right: inside a filter run, the < and > always replace the [ and ]. (Similarly, if transcluding instead of using a variable, { and } replace [ and ].)

Other examples:

[field:caption[spam]] will return tiddlers where the contents of the “caption” field are equal to “spam”
[field:caption<eggs>] will return tiddlers where the contents of the “caption” field are equal to whatever is contained in the variable <<eggs>> (notice how the < and > around “eggs” replace the [ and ] that were around “spam” in the first filter.)

[[cheese]get[caption]] will start with the tiddler titled “cheese” and then get whatever is in its “caption” field
[<list-item>get{baked-beans}] will start with the tiddler contained in the variable <<list-item>> (notice how the < and > around “list-item” replace the [ and ] that are around “cheese” in the first filter) and then get the contents of whatever field is contained in the tiddler “baked-beans”, for example, if {{baked-beans}} would display text then it would get the text field of whatever tiddler is contained in <<list-item>>)

1 Like