Transclusion of filter expressions in filtered transclusions

An audio widget I recently wrote requires the names of the local audio files to be played to be set in the widget’s attribute source. The list of audio files is variable and is created by the user by inputting a tiddlywiki filter expression in a text field. This filter expression is (currently) stored in the field search-expression of the player, e,g,
[regexp:performer[Demenga]get[file]]
The code of the player thus (currently) consists of just the following line:

<$audio source={{{ {{!!search-expression}} }}}/>

The transclusion, however, does not work.
The transclusion does work though if used with the ListWidget (not used in the player):

<$list filter={{!!search-expression}}/>

It correctly lists the file names (but does not give access to the list as an argument for the source attribute). It is only when the transclusion is used inside triple curly braces that it stops working. E.g., wikifying the filter expression does not help:

<$wikify name="search" text="{{!!search-expression}}">
{{{ <search> }}}
</$wikify>
// Result: <search>

It would be lovely if I could make the above single line of code work in one way or another.

Try this:

<$audio source={{{ [subfilter{!!search-expression}format:titlelist[]join[ ]] }}}/>

Notes:

  • subfilter{!!search-expression} evaluates the filter contained in the search-expression field of the current tiddler. This returns a space-separated, bracketed list of items. However, when using a filtered transclusion as a parameter value in a widget, only the first result in the list will be used as the parameter value.
  • So, to return the entire list of items, we need to construct a single value that contains the complete space-separated, bracketed list. To do this, we use format:titlelist[] to add brackets to items that contain spaces, and then join those results with spaces to produce the final single value. This result is then passed in the source parameter to your widget for further processing.
  • This same result can be achieved using a $set widget, like this:
<$set name="sourcelist" filter={{!!search-expression}}>
<$audio source=<<sourcelist>>/>
</$set>
  • This works because the $set widget evaluates the specified filter, and then automatically adds brackets and spaces as needed to produce a single value containing the desired space-separated, bracketed list. This result is stored in the sourcelist variable, which can then be passed along to the source parameter of your $audio widget.

Hope this makes sense… let me know how it goes.

enjoy,
-e

1 Like

Both solutions work.
Many thanks!