If we look at the Field edit cascade we can add the following filter;
[match[renewal-date]then[$:/custom/EditTemplate/fieldEditor/renewal-date]]
In this case it is a subfilter, a little research shows the input is the currentField name which is also available as <<currentField>> in subsequent transclusions and procedures such as the one above $:/custom/EditTemplate/fieldEditor/renewal-date.
However I wish to have a list of fieldnames, in the form that permits spaces etc… in the titles, such that if any one of these matches the input or variable “currentField” then the cascade will use the $:/custom/EditTemplate/fieldEditor/general-name.
I would like to document three forms;
- Using a list of fieldnames in a standard title list
- Using a list of fieldnames in a variable containing a list of titles
- Using a list of fieldnames in a multi valued variable MVV containing a list of fieldnames
In some ways it would be "as if we had an operator " so perhaps a custom function which also retrieves the fieldnames to test via a filter definition.
match.any<listVariable>
match.any(listVariable)
The value passed through is the first matched title.
For some reason this regularly confuses me because normally we use filter to apply to many titles, in this case we have one title and we want to test against many titles for a match.
- I am confident I can solve this but since its a reoccuring mind block I would love to see others ideas and document it.
Some options (matching <<currentField>> since you mentioned it; this could of course be any string/variable/transcluded value of choice):
\define titleList() A B C
\function mvvList() A B C
\function match.any(var) [all[]] :intersection[enlist<var>]
\function match.any.mvv(mvv) [all[]] :intersection[(mvv)]
1. A B C +[match<currentField>]
2. [enlist<titleList>match<currentField>]
3. [(mvvList)match<currentField>]
4. [<currentField>] :intersection[enlist<titleList>]
5. [<currentField>] :intersection[(mvvList)]
6. [<currentField>match.any<titleList>]
7. [<currentField>match.any.mvv(mvvList)]
This is a nonexhaustive list; you could also write helper functions using MVV/enlist<titleList> + match, for instance, though IMO this wouldn’t be more efficient than using +[match<currentField>] as-is unless you needed a two-parameter function for some reason.
A couple further variations on another style — less efficient than MVVs, IMO, but there may be use-cases in which this works better than enlist:
\define commaList() Multiword Title, Title With Spaces
\function match.comma.list(string) [all[]] :intersection[<string>split[, ]]
8. [<currentField>] :intersection[[Multiword Title, Title With Spaces]split[, ]]
9. [<commaList>split[, ]match<currentField>]
11. [<currentField>match.comma.list[Multiword Title, Title With Spaces]]
11. [<currentField>match.comma.list<commaList>]
I used , as the separator string for convenience and legibility, but you could use any separator of your choice. For nonstandard characters or characters that may cause confusion when used in a filter, I suggest supplying them as default parameters to the function:
\function match.any.string(string, sep:" | ") [all[]] :intersection[<string>split<sep>]
\define pipeList() Multiword Title | Title With Spaces
[<currentField>match.any.string<pipeList>]
[<currentField>match.any.string[This Time With Commas, Note the Second Parameter],[, ]]
Thank you Emily, i am confident most of those will work for me. In the case of the cascades currentField is passes to the filter so i will test if just providing;
-
‘:intersection[enlistthen[templatename]]’ may work, is this the general solution
-
a general solution that uses the fact the currentField value is given to the filter.
For the specific
I may look to some additional forms such as avoiding having to define titleList seperatly, with a sub filter
or
since currentField is known I may just test if a tiddler by that name has a field with a particular name and value eg field-edit-type[select-value]
or
retrieve its value and return it as the template name.
‘[get[field-edit-template]]’ if this truly is a subfilter with currentField tested for, as a field tiddler.