What is the syntax to run a macro when a button is clicked?
What have I tried?
I tried this syntax
<$button>
<$macrocall $name="jsontiddlers" filter="[[Test]get[text]]" $output="text/raw"/>
Hello
</$button>
The output is
Not sure where the extra [] comes from.
What am I trying to do?
I want to have a custom button to export my selected tiddlers in JSON format.
Try this:
<$button> export
<$action-sendmessage
$message="tm-download-file"
$param="$:/core/templates/exporters/JsonFile"
exportFilter="[[...]]"
filename="tiddlers.json" />
</$button>
Where the value for exportFilter is a filter syntax that supplies the titles of the desired tiddlers.
4 Likes
Thank you so much. I misread the official documentation and thought this macro is used for exporting the tiddlers into JSON. My bad.
Posting my final solution here, which someone might find useful.
<$button> export
<$set name="filter" filter="[[Test]get[text]]">
<$action-sendmessage
$message="tm-download-file"
$param="$:/core/templates/exporters/JsonFile"
exportFilter=<<filter>>
filename="tiddlers.json" />
</$set>
</$button>
How?
If you create a tiddler Test and fill it with some filters. Like
[prefix[$:/core/images/]]
[tag[TableOfContents]]
Then clicking on the button, which is given above, will export the tiddlers that match the filters in JSON format.
Why? (Use case)
I am exploring different ideas to easily sync my configuration across all my TWs.
One solution I have in mind goes like this
- Create a master copy of TW
- Configure it to your liking
- Collect the list of system and shadown tiddlers you configured in a tiddler, like
Config-List, using filters
- Export all the tiddlers in JSON using the button given above and import into new TWs
Using explicit filters in Config-List means I will not export frivolous shadow tiddlers.