Help on basic confusion between current tiddler being iterated in list and actual tiddler where we are

Hello all,

I’m still very new to Tiddlywiki and as many before me, I seem to be struggling with the syntax (also because many questions where answered before transclusion was a thing?)

In any case:

I have a tiddler named “Air spells”.

Inside that tiddler, I have a table listing all the tiddlers that have “Air spells” in their “college” field (the field value is same than the tiddler title listing them).
What I’m trying to do is very simple: use the title of the tiddler within the list macro to build said list. That way, the contents of those listing tiddlers can be the same for different values of the college field, I don’t have to type the value of the college since I’m grabbing it from the title of the listing tiddler.

Currently I have this content for the table:

<table>
<tr><th align="center">Spell name</th><th>Class</th><th>Base cost</th><th>Additional cost</th><th>Time to cast</th><th>Duration</th><th>Prerequisites</th><th>Notes</th></tr>
<$list filter="[tag[GURPS Spell]field:college[[title]]sort[]]" emptyMessage="<tr><td>No <<currentTiddler>> found.</td></tr>">
  <tr>
    <td align="left"><$link to=<<currentTiddler>> ><<currentTiddler>></$link></td>
    <td align="left">{{!!class}}</td>
    <td align="left">{{!!base_cost}}</td>
    <td align="left">{{!!additional_cost}}</td>
    <td align="left">{{!!casting_time}}</td>
    <td align="left">{{!!duration}}</td>
    <td align="left">{{!!prerequisit}}</td>
    <td align="left">{{!!Summary}}</td>
  </tr>
</$list>

… But I get an error [Filter error: Missing [ in filter expression](#Filter error: Missing [ in filter expression) ; of course if I replace [title] by Air spells it works.

Can someone explain to me what obviously basic mistake I am making, please?

Thank you! :slight_smile:

May be you have to use {{!!title}} instead [[title]]

Thanks for answering :slight_smile: Unfortunately, no, tried that, it doesn’t render anything :frowning:

1 Like

Within filter syntax, the brackets used around a filter operand indicate how that operand is to be interpreted:

For literal strings (e.g., “Air spells”), enclose the value in square brackets: [Air spells]
For variables/macros, (e.g., “currentTiddler”), enclose the variable/macro name in angle brackets: <currentTiddler>
For tiddler field references (e.g., “!!somefield”), enclose the field reference in curly brackets: {!!somefield}

Also note that within filter syntax brackets are NOT doubled.

Thus, for your usage, you could write either of these two filters:

<$list filter="[tag[GURPS Spell]field:college<currentTiddler>sort[]]">
or
<$list filter="[tag[GURPS Spell]field:college{!!title}sort[]]">

Note also that the <currentTiddler> or {!!title} value used in the filter syntax is the title in which the $list widget occurs, but within the CONTENT of the $list widget the value of the currentTiddler variable is set to each title found by the filter. This is what allows you to write {{!!class}}, {{!!base_cost}}, etc.

One last tip: when using the $link widget to show a link to the “currentTiddler”, you can write:

<$link to={{!!title}}>{{!!title}}</$link>

which can be further reduced to just <$link/> which uses the current title field value as the default for both the link to=... parameter and the link display text. Like this:

<td align="left"><$link/></td>

enjoy,
-e

3 Likes

I knew this was an @EricShulman question, I was just about to reply, better wait till you pop on!

So clear. So simple. Thank you @EricShulman !

Whenever I manage to produce a filter error, I review this https://pesky-brackets.tiddlyhost.com

Also, there’s a super useful mini-cheatsheet about filter syntax pitfalls here I can't pass a variable as parameter to a function - #2 by etardiff

1 Like