Passing a filter to a macro, when the filter includes replaceable parameters
- I would like to be able to pass filters to macros that make reference other replicable parameters in the macro. eg
Please consider the following macro
\define fieldname-value-select-macro(fieldname filter)
<$select field="$fieldname$"> default={{!!$fieldname$}}>
<$list filter='[all[shadows+tiddlers]each[$fieldname$]get[$fieldname$]sort[]]'>
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>
\end
<<fieldname-value-select-macro caption>>
- This works on tiddlywiki.com
- Here you can set the caption on the current tiddler to any of the existing caption values (unlikely use)
- Note how the select widget uses the filter below
[all[shadows+tiddlers]each[$fieldname$]get[$fieldname$]sort[]]
- This filter obtains all the existing values from $fieldname$
What does not work
- If I was to pass the filter above in a parameter to the macro, the macro would look like this
<<fieldname-value-select-macro caption "[all[shadows+tiddlers]each[$fieldname$]get[$fieldname$]sort[]]">>
- This does not work because the filter parameter includes
$fieldname$
which is not replaced by the value in the macro parameter fieldname (in this case caption)- if I used
filter="$filter$"
in the selects list widget.
- if I used
Desired result
- To make the above work out of the box, no doubt if even possible requiring a core change
- The $filter$ would need to be expanded, then the $fieldname$ within that expanded before passing to the list widget.
- Arguably any parameter would need to be expanded until if does not contain any other $param$
- A smart workaround to achieve the same result
- I believe if I set variables I can pass a filter that will be interpreted correctly (untested today) eg
-
[all[shadows+tiddlers]each<fieldname>get<fieldname>sort[]]
but what chance is there we can use the suggested approach?
-
- I believe if I set variables I can pass a filter that will be interpreted correctly (untested today) eg
Thanks in advance for your considered response