WidgetMessage: tm-new-tiddler with auto tagging

167 views
Skip to first unread message

vinvi...@gmail.com

unread,
Dec 15, 2020, 4:31:16 AM12/15/20
to TiddlyWiki
Hello,

I am using WidgetMessage: tm-new-tiddler.

I have a Template tiddler called "Template1" with fields, tags etc.
And a tiddler called "Template1Button" with this code:

<$button message="tm-new-tiddler" param="Template1Button">New tiddler</$button>

I transclude tiddler {{||Template1Button}} in different tiddlers. It all works fine so far.

How can I make sure that the newly created tiddler is also automatically tagged to the tiddler where the button is transcluded?

So when I click on the transcluded button in Tiddler1 the new tiddler should be automatically tagged to Tiddler1. And with Tiddler2 to Tiddler 2 etc.

Thank you,

Michael Wiktowy

unread,
Dec 15, 2020, 2:55:32 PM12/15/20
to TiddlyWiki
The action-createtiddler widget is similar but allows you to save the name of the created tiddler somewhere for subsequent actions.

The issue that I often have is that "subsequent" does not just mean further down the macro since actions can trigger in unpredictable ways. In this case, if you cram all the action together in one macro, the name of the tiddler does not get stored in time for the other actions to use it.

The way that I force things to act in a particular order is to create two groups of actions on the same button: one within the button widget and the the other in an actions macro called by the button. The one that is within the widget (i.e. $action-createtiddler) gets triggered first and then the "actions" get called (the $sendmessages/$action-navigate that use the output from the $action-createtiddler).

For instance, I think this recreates what you want to do:

\define buttonaction()
<$fieldmangler tiddler={{$:/temp/new_button_tiddler}}>
<$action-sendmessage $message="tm-add-tag" $param=<<currentTiddler>>/>
</$fieldmangler>
<$action-navigate $to={{$:/temp/new_button_tiddler}}/>
<$action-sendmessage $message="tm-edit-tiddler" $param={{$:/temp/new_button_tiddler}}/>
\end
<$button actions=<<buttonaction>>>New tiddler<$action-createtiddler $basetitle="Homemade Button" $template="Template1Button" $savetitle="$:/temp/new_button_tiddler">/>
</$button>

There might be simpler ways to do this.

/Mike

Mark S.

unread,
Dec 15, 2020, 4:34:09 PM12/15/20
to TiddlyWiki
Yet another approach:

<$button >New Task
<$vars left=" [[" right="]]" space=" ">
<$action-sendmessage $message="tm-new-tiddler" $param="TaskTemplate" 
   tags={{{ [[TaskTemplate]get[tags]addsuffix<left>addsuffix<currentTiddler>addsuffix<right>] }}}  />
</$vars>
</$button>

Mostly this demonstrates that when you use the <$action-sendmessage> widget, it will bundle up other fields and send them along.
So you could create different versions of the same button, but that add various fields (date, journal, author, etc.) without changing
the original template.


Michael Wiktowy

unread,
Dec 15, 2020, 11:10:42 PM12/15/20
to TiddlyWiki
I often struggle with filter syntax so thanks for the counter-example as I find those easiest to learn from.

In playing around with it, there is an interesting subtlety with Mark's solution that makes it slightly different/better.

If the template does not already exist:
1) it will not tag the new tiddler with <<currentTiddler>> but because you are using the template name as a basename, you are effectively creating the template from a blank tiddler. So that may be a preferred behaviour. It must be some nuance in how the filter will not continue if the [TaskTemplate]get[tags] fails to find something to get tags from and addsuffix not working on an empty list.
2) it will not ask for confirmation to delete the new tiddler if you click the trash can instead of saving your edit ... must be a consequence of the non-draft tiddler not existing yet and the text field being blank
3) it will not create anything if you just cancel out of the draft by clicking the X ... once again ... maybe that is the preferred behaviour.

Also, I was trying every operator to see if there was an alternative solution to manually wrapping the title with [[ and ]] using addprefix/suffix but there doesn't seem to be a replacement for the $vars/addprefix<left>/addsuffix<right> construction. I thought that enlist would do it but it just grabs the first word of the currentTiddler title. Maybe there ought to be an enlist:greedy or enlist:value that interprets the entirety of the input as a single title and wraps some [[]] around it.

A slight tweak to Mark's solution to tag with currentTiddler even when there is a missing template file (and make the space padding in the $vars optional) is:

...
<$action-sendmessage $message="tm-new-tiddler" $param="TaskTemplate"
tags={{{ [[TaskTemplate]get[tags]] +[<currentTiddler>addprefix<left>addsuffix<right>] }}} />
...

It still does 2) and 3) though.

I suspect that you could pack that right into the <$button message= ... param=... > like the OP but I don't know how one would format the paramObject=. There doesn't seem to be examples in the TiddlyWiki manual pages.

/Mike

Saq Imtiaz

unread,
Dec 16, 2020, 12:02:25 AM12/16/20
to TiddlyWiki

Also, I was trying every operator to see if there was an alternative solution to manually wrapping the title with [[ and ]] using addprefix/suffix but there doesn't seem to be a replacement for the $vars/addprefix<left>/addsuffix<right> construction. 


I am curious, what purpose is that serving here? 

Michael Wiktowy

unread,
Dec 16, 2020, 2:15:13 AM12/16/20
to TiddlyWiki
A tangent. I was just looking for a more concise/intuitive/automatic way to convert a title (or string in general) with spaces into a single title in a title list rather than each word being separate.

I get caught up by manipulating/building Title Lists to use as tags frequently. I guess the official/only way is the way Mark indicated but it always seems quite manual defining the [[ ]] end caps and then gluing them on with addsuffix/prefix.

Looking through the other filter operators, it seemed that:

1) title<currentTiddler>
2) field:title<currentTiddler>
3) each:value<currentTiddler>
4) enlist<currentTiddler>

could function to wrap a multi-word currentTiddler title in [[ ]] but they don't work that way it seems.

I'm just poking and prodding to fill in gaps in my understanding.

/Mike

Mark S.

unread,
Dec 16, 2020, 9:56:18 AM12/16/20
to TiddlyWiki
I can explain what I think is happening. In reality, I just keep pounding until something works.

When assigning directly via = the {{{ code }}} returns a string formatted to look like a title list. Unfortunately, different runs inside are separated by a carriage return. The = assignment truncates after the carriage return.

So if you simply try something like this:

tags={{{ [{TaskTemplate!!tags}][<currentTiddler>] }}}  />

Current Tiddler will disappear. So you need the + in order that everything will get output as one string with no c/r. 

But if you use +, then you have to do something to every item in the first run. You can't just use addsuffix<currentTiddler>, because if you do,
and if the current tiddler has spaces in it's name, the generated string will look like each word in the current title is a tag. Thus you need to
add the brackets. This means that internally the current tiddler must be appended for every tag in the template, but de-duplication handles that.

Mark S.

unread,
Dec 16, 2020, 10:00:16 AM12/16/20
to TiddlyWiki
On Tuesday, December 15, 2020 at 8:10:42 PM UTC-8  wrote:
I often struggle with filter syntax so thanks for the counter-example as I find those easiest to learn from.

In playing around with it, there is an interesting subtlety with Mark's solution that makes it slightly different/better.


I admit my approach is a kludge. It was just submitted as an alternative. It has the advantage of being slightly easier to read. Yours is probably the proper way to do such things.
 

Michael Wiktowy

unread,
Dec 16, 2020, 10:52:34 AM12/16/20
to TiddlyWiki
Looking at the OPs format ... while these other options (sticking things in an actions macro in the widget or in the actions= or transcluding a filter into the button field= options) are available, could someone illuminate the formatting of the "hashmap" that needs to be provided with paramObject= if you want to use <$button message="tm-new-tiddler" param="Template1Button" paramObject= ...> and try to feed the tags in that way using Mark's method? Every message seems to have a paramObject option but none of the manual pages have an example of its use.

Thanks,
/Mike

Mark S.

unread,
Dec 16, 2020, 12:34:01 PM12/16/20
to TiddlyWiki
Looking at the code for the Button widget, I don't see any place where paramObject  gets populated. I do see it for the send-message widget. So I'm guessing that you can't use "paramObject" with the button widget without hacking the button widget code.

TW Tones

unread,
Dec 16, 2020, 9:43:19 PM12/16/20
to TiddlyWiki
FYI:

In a button you do not need to use messages or params in the button but can use actions= <<action-macroname>> to drive the actions. you can also place actionwidgets inside the button, even wrapping them in lists or conditionally. Use the actionSend message widget etc... Then rather than paramObject param etc.. you can supply the fieldname="value" fieldname1={{transcluded}} fielname2=<<var>> to the action widget.

The term hash map is almost obsolete in tiddlywiki at a wikitext level, so either it should be described or deprecated in the documentation.

Tones

vinvi...@gmail.com

unread,
Dec 19, 2020, 5:51:11 AM12/19/20
to TiddlyWiki
Thanks, this is what it ended up being;


\define Tags() [[$(currentTiddler)$]] [[(EXTRA-TAG)]]

<div style="float:left;"><$button>
<$action-sendmessage $message="tm-new-tiddler" 

title="TIDDLER-NAME" 
text="TEXT-FIELD-HERE" 
tags=<<Tags>> 
field="FIELD-TEXT" 
field2="FIELD-TEXT"

/>
<span style="color:black;">''BUTTON-NAME''</span>
</$button></div>

Op donderdag 17 december 2020 om 03:43:19 UTC+1 schreef TW Tones:
Reply all
Reply to author
Forward
0 new messages