Using Variable-substitution Within Filter Strings

(Hopefully I’m following nettiquete here, as reviving old post is fine on this list).

Thanks for this. Recently I used something similar but my filter was something like:

[modifier[$modifier$]!is[system]!has[draft.of]days:modified[<<previousTo $days$>>]]

(where <<previousTo value>> just gives value - 1 to increase readability).

There is a way to use macro arguments like modifier attached to the exporting file name of the button action? I would like to have something like filename=$modifier$+"recent.json", so if modifier user is Jhon Doe, the exported JSON file with the tiddlers would be named jhon-doe-recent.json

TIA.

The $modifier$ is only valid inside the depricated macro \define and you do not document this.

Your “previouse” macro can’t be used in a filter.

Please give us more of the context.

Tip:

What you are trying to do is concatenate or substitute things in a string. There is a lot of discussions here on this subject. The new substitute operator, the back tick attribute value method.

Thanks for your quick answer. And here are more details.

Here is the complete source code of the macro and the particular macro I’m trying to modifiy is called modifiedBySinceDaysAgo(modifier, days) and here an example of its usage.

Notice that <<modifiedBySinceDaysAgo Offray 5>> is time sensitive, so it gives different answers when I visit the wiki. If I visit the wiki 5 days after the modification, the result will be empty. If fact, that makes me think that what I like is something like <<lastModificationsByUpTo modifier amount>>, that takes all the modifications by a particular modifier and select the last amount defaulting to a particular quantity. But that is a matter of changing the filter.

To explain myself better: my question now is how the result of a particular macro can be saved with a button, including a particular parameter given to such macro. So, instead of saving into the generic tiddlers.json, we could get something like jhon-doe-recent.json, where jhon-doe is a parameter given to the filter.

In your macro, you have:

<$button dragFilter=<<filter>> > export tiddlers
<$action-sendmessage $message="tm-download-file"
   $param="$:/core/templates/exporters/JsonFile"
   exportFilter=<<filter>>
   filename="tiddlers.json" />
</$button>

To use a different target filename (instead of “tiddlers.json”), you could change the filename parameter of the tm-download-file message to something like this:

filename={{{ [[$modifier$]slugify[]addsuffix[-recent.json] }}} />

Notes:

  • The slugify[] filter operator (see https://tiddlywiki.com/#slugify%20Operator) ensures that the resulting filename won’t have any spaces or other characters that are usually not permitted by your local filesystem. So if the $modifier$ has a value of “Jhon Doe” (i.e., containing capital letters and spaces), it will automatically be converted to “jhon-doe” for use by tm-download-file

enjoy,
-e

2 Likes