Link from multiple values in a field

Hi,

I have a series of tiddlers which have a field ‘key’ which contains multiple values and this produces a unique list of those values:

<$list filter="[get[key]enlist-input[]unique[]sort[]]">

</$list>

It would be even more amazing if each entry in the list would then link to the tiddlers which contain that value. Is that possible?

Thanks
Jon

Hi Jon

I’m assuming you mean that the tiddlers you want to link to are other ones which contain the values from the key field in their own key fields? In that case I think you want something like the following:

[list[!!key]unique[]sort[]] :map:flat[all[tiddlers]contains:key<currentTiddler>]

Explanation:

  • I’ve replaced your initial get[key]enlist-input[] construction with list[!!key], which is a slightly more concise way of looking in the list field of the current tiddler and getting the titles listed in that field
  • The second filter run does a few things:
    • The map prefix takes the titles from the first filter run, and then runs the next filter run once for each of them, setting currentTiddler to each title in turn
    • Normally the map prefix only returns the first title from each time it runs, but the :flat modifier ensures it returns all of the titles each time
    • The inside of the run itself them starts with all tiddlers in the wiki (rather than just the item for the map run), and uses the contains operator (with the suffix key, which can be the name of any list field to look in) to get all tiddlers which list the currentTiddler in that field (which inside the map filter run means each of the titles returned by first filter run)

Hopefully that makes sense and helps you understand?

Jon,

Here’s a demo of what I think you’re looking for in action:

The field I’m using is vocabulary — but as with your key field, it’s functioning as a list of values. Each value (at least in my case) has a home tiddler, so I do want a link directly to that item, but I can also include a link to each of the tiddlers that list that term in their “vocabulary” field. I accomplish this by using a second list widget nested within the first, using the listed filter operator.

For visual ease, I present this as a table:

<table>
<$list filter="[get[vocabulary]enlist-input[]unique[]sort[]]">
<tr>
<td><$link/></td>
<td><$list filter="[<currentTiddler>listed[vocabulary]]"/></td>
</tr>
</$list>
</table>

EDIT: I think a more semantic way — one that may be easier to follow for novices at this forum, and one that my future self could trouble-shoot or tinker with more easily — is to use a clearly-named variable in the outer list, rather than letting <currentTiddler> track the current value within the outer list widget:

<table>
<tr>
<th>vocabulary term</th>
<th>tiddlers listing this vocabulary term</th>
</tr>
<$list filter="[get[vocabulary]enlist-input[]unique[]sort[]]" variable="this-vocab-term">
<tr>
<td><$link to=<<this-vocab-term>>/></td>
<td><$list filter="[<this-vocab-term>listed[vocabulary]]"/></td>
</tr>
</$list>
</table>
1 Like

Many thanks for your detailed reply and that does help me understand what’s going on.

If I just replace what I had with your update like this:

<$list filter="[list[!!key]unique[]sort[]] :map:flat[all[tiddlers]contains:key<currentTiddler>]">

</$list>

then unfortunately, there is no output but as I’m very much a noob at the ‘cut & paste’ stage of TW, I don’t know why that might be. I’ve played around with it to no avail - sorry.

Springer that works perfectly and I’ll study what you and Exile have referred to so I can understand this stuff a bit better.

Many thanks
Jon

1 Like

Jon, I think the @exilegreen approach was assuming that you were wanting to display, within a tiddler (or in a view template within each tiddler), a set of links to other tiddlers whose key field contents overlapped with the key values in the current tiddler. The !!key notation would pull contents from the current tiddler’s key field, rather than grabbing all the values that exist in that field throughout your wiki.

Meanwhile, I read your code attempt as aiming for a single big-picture overview of all the terms in your wiki that are listed anywhere within any tiddler’s key field, so that’s what the vocabulary overview demo (linked above) provides a model of.

1 Like