Is it possible to specify filterrun suffixes as variables?

Hello,

I’m trying to get two variables into a filter of this format:

[list<storyList>search:<myFields>:<myFlags>{$:/temp/search/input}]

Is there a way this can be made to work?

EDIT: to be precise, the problem are the suffixes of the search filter

Thank you,
Simon

The easiest way is to create a function and within that use the substitute operator to construct the result;

Something like this, but not actually this;

\function  new-filter() [[search:$(myFields)$:$(mySuffixes)$]substitute[]] +[join[]]

<$let myFields=" a b" mySuffixes="$:/">
<<new-filter>>

A before bed tip, I hope it gets your further.

I learned this approach from someone when I asked how to use values in filter prefixes the answer included the new substute operator.

1 Like

Thank you @TW_Tones

with your approach I found a solution!

It looks like this (don’t laugh :grinning:)

\function tf.search-tiddlers() [[list]addsuffix[<tv-story-list>]addsuffix[$(suffix)$]substitute[]addsuffix[ ]addsuffix[:filter]addsuffix[$(prefix)$]substitute[]addsuffix[{$:/config/tiddlyflex/story-river/filter}match]addsuffix[$(prefix)$]substitute[]addsuffix[yes]addsuffix[$(suffix)$]substitute[]addsuffix[then<currentTiddler>!is]addsuffix[$(prefix)$]substitute[]addsuffix[draft]addsuffix[$(suffix)$]substitute[]addsuffix[search:]]  ${$(searchFields)$}$ +[substitute[]] +[join[]] +[addsuffix[:]] ${$(searchFlags)$}$ +[substitute[]] +[join[]] +[addsuffix[$(prefix)$]substitute[]addsuffix{$:/temp/search/input}addsuffix[$(suffix)$]substitute[]] +[addsuffix[else{$:/config/tiddlyflex/story-river/filter}!match]addsuffix[$(prefix)$]substitute[]addsuffix[yes]addsuffix[$(suffix)$]substitute[]addsuffix[then<currentTiddler>]] +[join[]] +[addprefix[$(prefix)$]substitute[]addsuffix[$(suffix)$]substitute[]] +[join[]]
\procedure tiddlyflex-filtered-story-list()

<$vars prefix="[" suffix="]">

<$list filter=<<tf.search-tiddlers>> history=<<tv-history-list>> template="$:/core/ui/StoryTiddlerTemplate" storyview="tiddlyflex"/>

</$vars>

\end

Thanks again,
Simon

The tf.prefix for global functions should be reserved for tiddlywiki core. Simialr to tc-classes or tm-message. The tf.dot is needed to be able to use function definitions as functions in filters.

Users should use f.prefix for global functions which should be OK. It’s also shorter :slight_smile:
_f.localFunction should also be used by users.

I personally think I’ll use wlf.prefix or something similar for wikilabs functions.

I did some explanation for the new naming rules at the toc-rewrite draft PR

1 Like

Thanks for the explanation @pmario

I think I’ll adjust my variable, function and class names then

I am not laughing @BurningTreeC and I am glad it works. I am impressed by its length :clap:

However I would be confident there is, or should be a MUCH better way.

Function names and prefixes

Also I have a different view to @pmario and prefer readable than prefixed names, but I do deploy a number of strategies to support this, although I will not detail it here.

  • This difference of opinion is healthy in my view :nerd_face:
  • It is also heavily context dependant, such as is it only in a particular wiki, or something shared widely?

However lets simply refactor your solution;

\procedure tiddlyflex-filtered-story-list()
   \function tf.search-tiddlers() [[list]addsuffix[<tv-story-list>]addsuffix[$(suffix)$]substitute[]addsuffix[ ]addsuffix[:filter]addsuffix[$(prefix)$]substitute[]addsuffix[{$:/config/tiddlyflex/story-river/filter}match]addsuffix[$(prefix)$]substitute[]addsuffix[yes]addsuffix[$(suffix)$]substitute[]addsuffix[then<currentTiddler>!is]addsuffix[$(prefix)$]substitute[]addsuffix[draft]addsuffix[$(suffix)$]substitute[]addsuffix[search:]]  ${$(searchFields)$}$ +[substitute[]] +[join[]] +[addsuffix[:]] ${$(searchFlags)$}$ +[substitute[]] +[join[]] +[addsuffix[$(prefix)$]substitute[]addsuffix{$:/temp/search/input}addsuffix[$(suffix)$]substitute[]] +[addsuffix[else{$:/config/tiddlyflex/story-river/filter}!match]addsuffix[$(prefix)$]substitute[]addsuffix[yes]addsuffix[$(suffix)$]substitute[]addsuffix[then<currentTiddler>]] +[join[]] +[addprefix[$(prefix)$]substitute[]addsuffix[$(suffix)$]substitute[]] +[join[]]

<$vars prefix="[" suffix="]">

<$list filter=<<tf.search-tiddlers>> history=<<tv-history-list>> template="$:/core/ui/StoryTiddlerTemplate" storyview="tiddlyflex"/>

</$vars>

\end

By simply placing the “concatenation” function tf.search-tiddlers inside the other you can use any name you want, as it is local to that function, even if the outer one is global.

  • I am also tempted to split that functions definition across lines to make it more readable, but if we had a more general solution to this issue this would be less important.

The more general issue

As I see, it this issue you raised is a type that belongs to a class of problems, that I have tried to address in the past. As yet I dont have a satisfactory approach:

  • using variables and transclusions as prefixes to filter operators.
  • more generaly constructing filters using variables and transclusions that can then be displayed as text for documentation and/or also used as a filter.