Transclude field value in a filter

I am trying to use the value of a field to display a list of tiddlers having a tag the same as that field value.

Looking online I found an answer by @EricShulman to a earlier post in which he wrote

<<list-links filter:"[tag[$(title)$]] +[sort[title]]">>
Reference:https://groups.google.com/g/tiddlywiki/c/INiJgqCpmXo

I thought, this was would to do what I wanted if I replaced title by my field name, item_type, produce a list of all tiddlers having a tag whose value is defined by the field item_type in the current tiddler.

I can not get this to work.

My tiddler code is:

Select the type item: <$select field="item_type" default="Items">
<option>35mm Negative</option>
<option>Book</option>
<option>Catalogue</option>
<option>Essay</option>
<option>Exhibition Price Sheet</option>
<option>Exhibition Review</option>
<option>Invitation</option>
<option>Items</option>
<option>Letter</option>
<option>Newspaper</option>
<option>Obituary</option>
<option>Page</option>
<option>Photo</option>
</$select>

<<list-links filter:"[tag[$(item_type)$]] +[sort[title]]">>

Any clues?

bobj

2 Likes

Try this instead:

<<list-links "[all[current]get[item_type]] +[tagging[]sort[title]]">>

The first part of the filter gets the item_type field from the current tiddler, then passes it on to the second part which finds all tiddlers with that tag and sorts them.

$(...)$ is used to reference macro parameters and not the current tiddler’s field. That’s probably why it is not working.

2 Likes

You may also try [tag{!!item_type}]

2 Likes

Ooo… thank you… for a while now I’ve been thinking that such a thing would be really useful and here it is. So useful (am I allowed to award a :star: ?).

Very nice idea. I might want to go one step further, and choose the options as those Tag Tiddlers that themselves have a certain tag, like, say, TableOfContents:

Select the type item: <$select field="item_type" default="Items">
<$list filter=[tag[TableOfContents]]>
<option>{{!!title}}</option>
</$list>
</$select>

<<list-links "[tag{!!item_type}] +[tagging[]sort[title]]">>

This should work on the main site, or anything with some tiddlers tagged TableOfContents:

TOC_Select.json (345 Bytes)

1 Like

Thanks to all who suggested possibilities. I got the code working but realised that it would be better for me to compare against the value of a type field in every item tiddler rather than a tag value. On creation, every item tiddler gets a object_type field with its value being one of the options in the $select statement.

''Select the type of item you are interested in from the dropdown below. To see all items, use click [[Items]]''

Item type: <$select field='item_type' default="Items">
<option>35mm Negative</option>
<option>Book</option>
<option>Catalogue</option>
<option>Essay</option>
<option>Exhibition</option>
<option>Exhibition Price Sheet</option>
<option>Exhibition Review</option>
<option>Invitation</option>
<option>Letter</option>
<option>Newspaper</option>
<option>Obituary</option>
<option>Page</option>
<option>Photo</option>
</$select>

The following is the list of items types you have selected.
<<list-links filter:"[field:object_type{!!item_type}]+[sort[title]]" emptyMessage:"Sorry nothing of that type found">>

So, studying the filter syntax documentation, I concluded the list-links statement above might work, and it does!!

Thank you everyone for your patience but I think I am getting the hang of it

Onward and upward…

bobj

You can do this by tagging your tags…
Create a tiddler entitled “35mm Negative” and tag it “Item Type”.
Proceed the same for every option in your list.
Then you can use this code (untested, and adapted from @Scott_Sauyet’s code and yours):

Select the type of item you are interested in from the dropdown below. To see all items, select //Items//.

Item type: <$select field='item_type' default="Items">
<$list filter=[tag[Item Type]]>
<option>{{!!title}}</option>
</$list>
</$select>

<<list-links filter:"[tag{!!item_type}] +[tagging[]sort[title]]" emptyMessage:"Sorry nothing of that type found">>

Fred

Thanks @tw-FRed I’ll give that a go.

bobj

And how do you display an additional colored field - eg. created - in the output list?

The <<list-links>> macro only produces a simple bullet list of links.
To produce custom list output, you need to use the <$list> widget.

Something like this:

<ul>
<$list filter="[tag{!!item_type}sort[]]" emptyMessage="Sorry, nothing of that type found">
   <li>
      <$link/>
      @@color:red;
      <$text text={{{ [{!!created}format:date[DD MMM YYYY]] }}}/>
      @@
   </li>
</$list>
</ul>
1 Like

Thanks @EricShulman, works perfect :slight_smile:

I have worked out how to have a identical <option>...</option> statements in more than one <select> statement.
Just create a tiddler with each of the available options and then instead of typing the various <option> statements in the <select> statements, just type {{tiddlername}} where tidddlername is the name of the tiddler containing the options.

This way, I can make sure that my create and select tiddlers always use the same list.

You can also generate them with a list.