Adding custom actions when saving a tiddler

Earlier today in the TiddlyWiki Discord server (see https://discord.com/invite/HFFZVQ8), @gavcloud asked:

As this seems to be a relatively common question that has been asked before, I’m sharing my reply here:

First, edit shadow tiddler $:/core/ui/EditTemplate. In the “save-tiddler-actions()” macro definition, add <<save-tiddler-custom-actions>> just before the <<delete-edittemplate-state-tiddlers>>.

Then, create a new tiddler (e.g., “MyCustomSaveActions”), tagged with $:/tags/Global, and enter the following wikitext code:

\define save-tiddler-custom-actions()
<$list filter="[<currentTiddler>tag[Bookmark Tag]]" variable=none>
<$action-sendmessage $message="tm-add-field" $name="view" $value="[sort[title]]"/>
</$list>
\end

Now, whenever the core save-tiddler-actions() macro is triggered by pressing the “done” button or by using the ctrl-enter keyboard shortcut, your save-tiddler-custom-actions() macro will also be invoked… and, if the tiddler is tagged with “Bookmark Tag”, the tm-add-field action will automatically add a view field containing [sort[title]].

Of course, this technique can be used to add all sorts of “automatically create/set a field” handling side effects when saving a tiddler… and, if you want to “automatically add a tag”, you can use a tm-add-tag message instead of (or in addition to) the tm-add-field message:

<$action-sendmessage $message="tm-add-tag" $param="sometag"/>

enjoy,
-e

6 Likes

I’ve asked a similar (if not identical) question recently Are tiddler save hooks possible?

Also see https://all-button-actions.tiddlyhost.com which is mentioned in that thread.

Edit: This Tix v0.10 — A Novel Tiddler Experience also popped up in a recent discussion about fonts, if you try to edit a tiddler, you will see multiple save buttons that work differently. I only bookmarked this, did not look at implementation yet, but perhaps @telmiger could comment on this.

Oh no :frowning:

Are there any public logs online?

While I’ve never used (and never will use) Discord, I don’t mind people using it for banter and private chats. Albeit I know one case when an unfortunate decision to completely shift the main place for community interaction from a classic forum to Discord (not the case of TiddlyWiki though) has ruined said community in one year. I’d like to think I’m not an anti-Discord zealot, yet when it’s about technical topics, that remains locked behind a gate and non-participants never get access to that knowledge.

I don’t think you need to worry about Discord replacing this forum; the Discord server actually predates Talk TW, and it hasn’t fractured the community yet. :wink: I’m a member of the server too, and Talk TW has always been substantially more active — and we regularly refer people here.

I suspect some people simply prefer the format (using Discourse on a phone is a headache!) or find it less intimidating to ask a question in Discord. Personally, I think it’s nice that TW fans can find a welcoming community no matter their preferred format!

4 Likes