Problem with tm-remove-tag message

67 views
Skip to first unread message

Ken

unread,
Apr 26, 2021, 4:28:56 PM4/26/21
to TiddlyWiki
I am having a problem getting a fairly simple process working in TiddlyWiki.

I want to create a new tiddler based on a template. The template includes a Templates tag so I can see all my templates in my TOC. When I create a new tiddler using the template, I want to remove the Templates tag.

The name of the template tiddler is "Source Tiddler". In a button, I use $action-createtiddler. Because the title of the created tiddler may be different from what's specified in the $basetitle attribute, I supply the $savetitle attribute with a place to store the actual title. In the code below I used a field in a temporary tiddler ($:/temp/create!!actual-title). I then try to remove the Templates tag from the newly created tiddler, as show in the $fieldmangler widget in the code. 

<$button>
<$action-createtiddler
 $basetitle="Created Tiddler"
 $savetitle = "$:/temp/create!!actual-title"
 $template="Source Tiddler"/>

<$fieldmangler tiddler={{$:/temp/create!!actual-title}}>
<$action-sendmessage 
 $message="tm-remove-tag"
 $param="Templates"/>
</$fieldmangler>

<$action-deletetiddler $tiddler="$:/temp/create"/>
Create New Tiddler
</$Button> 

This creates the new tiddler, and stores the correct value in the field (which I verified by commenting out the action-deletetiddler code). However, the tag does not get removed. I have tried storing the actual title in a field in the tiddler containing the button and in the text of a new tiddler, but cannot seem to figure out the correct syntax to use so the $fieldmangler widget correctly sets the currentTiddler. 

Note that if I hard code the $fieldmangler widget as follows, the tag is correctly removed!

<$fieldmangler tiddler="Created Tiddler">

So I would like advice on 1) Where should I store the savetitle and 2) what is the appropriate syntax to use for the tiddler attribute in the $fieldmangler widget?

Thank you.

Ken

Mark S.

unread,
Apr 26, 2021, 4:54:53 PM4/26/21
to TiddlyWiki
By using the actions attribute, you can add the things that have to happen AFTER the creation -- otherwise the button widget doesn't see the new tiddler.

\define myactions() 
<$fieldmangler tiddler={{x:/temp/create}} >
<$action-sendmessage 
 $message="tm-remove-tag"
 $param="Templates"/>
</$fieldmangler>

<$action-deletetiddler $tiddler="x:/temp/create"/>
\end

<$button actions=<<myactions>> >
<$action-createtiddler
 $basetitle="Created Tiddler"
 $savetitle = "x:/temp/create"
 $template="Source Tiddler"/>

Create New Tiddler
</$button> 

I changed your savetitle tiddler name while testing. Also, I kept things simple by not using a field since you were going to delete the tiddler anyway.

Ken

unread,
Apr 26, 2021, 6:48:22 PM4/26/21
to TiddlyWiki
Thank you Mark S.!

I believe I understand now. 

The widgets within the body of the $button widget happen as part of the button definition only - nothing actually happens until the button is pressed. Since the tiddler has not yet been created, the tiddler $:/temp/create has not been created and therefore the new title is not available in this context.

When the button is pressed, the action-createtiddler is executed as defined, thus creating the new tiddler and saving the actual title in $:/temp/create as requested.

Once the button has finished doing its job, the actions in the actions attribute are executed. At this point the new title is available for the $fieldmangler widget to access, and the tm-remove-tag message can work as expected.

Pardon my detailed explanation, but I needed to work through it and thought it might be helpful for others.

It makes total sense to me now. I just wish I was more comfortable with all the subtleties of widgets, macros and messages. Sometimes I get totally lost when trying to do something very simple! 

Thank you again for taking the time to help me.

Ken
Reply all
Reply to author
Forward
0 new messages