Run input as a filter is impossible?!?!

I can’t figure out how to do the simplest thing.

I have a filter that is going to run with a single title as its input. It needs to run two of those title’s fields as filters and add their output to its output. For various technical reasons, I cannot use outside variables, and currentTiddler cannot be set prior.

I was three layers deep with subfilter[] and :map:flat before giving up. How is this so hard? Is there really no filter that runs input titles as filters? Like [runfilter[]] or something like that? Then I could do [all[]get[fieldA]runfilter[]] [all[]get[fieldB]runfilter[]] and be done with it.

Something like [all[]get[fieldA]] :map:flat[subfilter<currentTiddler>] works, but it doesn’t work for TWO fields.

[all[]get[fieldA]] :map:flat[subfilter<currentTiddler>] [all[]get[fieldB]] :map:flat[subfilter<currentTiddler>]

This fails because the input of the first field filter gets sent into the second.

Does anyone have any ideas?

I simplified the problem too much. I should probably add that the output of each filter is manipulated. Let’s say in this case they get prepended with “fieldA-” or “fieldB-” I.E.

[all[]get[fieldA]runfilter[]addprefix[A-]] [all[]get[fieldB]runfilter[]addprefix[B-]]

Thus the two filters can’t be packed together and sent into a map prefix.

1 Like

Maybe you could create a custom function?

A custom function would require the use of an outside variable. This is something I’m doing as part of a tiddlymap filter, so I don’t have access to anything like that.

this is posible

<$list filter=`[${[[tida]get[afield]]}$reverse[]] [${[[tidb]get[anotherfield]]}$]` />

Can I pester you to show sample values for field A and for field B?

1 Like

Anything, it varies. fieldA could be [tags[myTag]] and fieldB might be [[TiddlerX]] [[TiddlerY]]. I’m trying to get TiddlyMap to extract the results of each tiddler’s two fields to use as edges. So in some cases, those fields will even be blank.

@buggyj, That would probably work, except in my case, I can only use a filter. I can’t rely on attribute substitution to custom make the filter on the fly.

Why couldn’t you use something like this?

\function run.filter(title,field) [<title>get<field>]:map:flat[subfilter{!!title}]


input title: <$edit-text field="input"/>

fields of input title: ({{!!input}})

<$tiddler tiddler={{!!input}}>

* field1: <$edit-text field="field1"/>
* field2: <$edit-text field="field2"/>

</$tiddler>


{{{ 

[run.filter{!!input},[field1]addprefix[a]]
[run.filter{!!input},[field2]addprefix[b]]

 }}}

demo on share

Preview:

1 Like

Because I can’t use outside variables, and functions are outside variables. It’s got to be one static filter. At best, I can use {!!references} to access filters in fields from global tiddlers. But those won’t be functions.

To clarify, all I can do is input a filter into a single edit-field. That filter will be passed a single title as an input. It won’t have currentTiddler set, and it won’t import any globals, or anything really.

It’s probably easier just to say I can’t use any variables at all, unless they somehow get defined within the filter.

The best I was able to do is this, but this will only work if all you need to do is add a simple prefix, things like that :confused:


[{!!input}get[field1]]
:map:flat[subfilter{!!title}addprefix[a-]]

[{!!input}get[field2]]
:map:flat[subfilter{!!title}addprefix[b-]]

:map[{!!title}search[b-a]removeprefix[b-]else{!!title}]

I suppose you can’t do this ?

[subfilter{TiddlerInput!!field1}addprefix[a-]]

[subfilter{TiddlerInput!!field2}addprefix[b-]]

If you can only pass the name of the input tiddler, IMO we would need a way to apply the filter of the second field only on parts of the titles in input, and without custom oeprators I don’t see how :confused:

That first one works sort of. It hopes that I don’t get any output from the filters that starts with “b”.

And yeah, it looks like you’re seeing the problem with your second options.

I’m starting to think there just isn’t a way to do what I want, which really seems silly. It’s not that hard. We have [each[X]] which fetches the field X of every input title. [each:list-item[X]] uses the the field X of every input title as a list. You’d think there’d be a [each:filter-item[X]] or something like that which would use the field X of every input title as a filter.

But there’s nothing like that.

Edit: Thanks for trying though. I spent two hours on the problem this morning.

Maybe the cascade filter run could be extended with a “flat” prefix, right now it only gives the first filter with results, it would make sense to be able to evaluate ALL filters https://tiddlywiki.com/#Cascade%20Filter%20Run%20Prefix

This wouldn’t help with your requirement of being able to add different prefix on each filter run tho

The cascade filter would have worked perfectly in this case, better than you think once I’d have factored in all the other fluff I’d cut out of this problem to simplify my question. But you are correct that it only returns the first result.

I got so excited earlier too when I looked into cascade.

This issue seems to arrise from the fact you are modifying existing code. I have pointed out previously a tendency to unnecessarily try to force things into one filter. This is what we may describe as nested filters.

However there is much more utility in nesting filters through the use of nested list widgets, the performance is they same and they are often easier to read. Nested lists;

  • allow you too generate a list item variable for each filter/list
  • give you a counter variable for each filter/list

Because you are retrofitting and modifying existing code if you wish to build a nested filter in a single filter this can be done with the “Filter Runs” and the new custom functions.

This does not ring true to me! However are you looking to have more than one output from your filter?

I have become quite adept at using functions so if you could instead present this as a minimalist test case we can use on tiddlywiki.com I would be happy to help.

this can be done with the “Filter Runs” and the new custom functions.

Okay, but again, I can’t do that. Those would be outside variables. I get what your saying that making nested lists can give cleaner solutions. But I literally can’t in this case. I’m not modifying any code. I have a single text-field where I can put a filter. That filter will not have access to any variables. TiddlyMap isn’t built that way.

This does not ring true to me! However are you looking to have more than one output from your filter?

In this particular case, it’s custom edge labels. But it could just as easily be a magic-edge-type which can describe multiple edges spawning from a node. Why does it have to be a single result?

I have become quite adept at using functions so if you could instead present this as a minimalist test

I welcome any help, but the case I gave is already the minimalist test case. If I gave a setup in a tiddler for people to poke at, people will come back with tricks like wrapping it in <$let> or putting \function at the top. I can’t use those solutions. I have to work with the text-box provided by TiddlyMap modal.

Could you put up an example wiki, with TiddlyMap, some sample test data and a reference to your desired change?

Its not so much a single result, but not two different single results at once. The problem is in this case, is it is hard to visualise the bind you are in.

Here, I think this largely captures the problem.

| fieldA | <$edit-text field="fieldA"/> |
| fieldB | <$edit-text field="fieldB"/> |

!! Solution filter:
<$edit-text tiddler="$:/temp/solution" placeholder="This filter receives this tiddler as input. It will not have currentTiddler or any other variables set."/>

|! Expected |! Actual |
| <$list filter="[subfilter{!!fieldA}] [subfilter{!!fieldB}]" join="<br>"/> | <$genesis $type=$vars $names="[variables[]]" $values="[variables[]then[]]" _private=`[[$(currentTiddler)$]subfilter{$:/temp/solution}]`><$list filter=<<_private>> join="<br>" /></$genesis> |

You’re not allowed to edit the tiddler.

1 Like

I am testing this on TiddlyWIki.com any suggested filters?

  • [tag[TableOfContents]] & [has[caption]]

Do I understand correctly that the code you want to use is similar to this?

<$genesis $type=$vars $names="[variables[]]" $values="[variables[]then[]]" _private=`[[$(currentTiddler)$]subfilter{$:/temp/solution}]`><$list filter=<<_private>> join="<br>" /></$genesis>

or just this?

`[[$(currentTiddler)$]subfilter{$:/temp/solution}]`