Unusedtitle Macro in button does not always work

Hello,

I have made a button that creates 3 tiddlers. The names of these tiddlers are made with the unusedtitle Macro with a given base, separator and count value (template). It works pretty good.

But

  • I can only make one new group of tiddlers with a correct name.
  • After that, clicking the button results in a new group of tiddlers but now with the same name and 00 (incl. space character) placed at the end of the name.
  • Clicking again results in the same name with 01, 02, etc.

The only way to get correct results is to explicitly save the wiki and refresh the browser. Clicking the browser after those actions gives a good result.

  • Does anyone know why this is ?

  • And, more importantly, how to change this behavior.

Browser is Vivaldi latest
Tiddlywiki 5.2.3 latest
OS is windows 10
timimi for saving

Kind regards,
Trend.

Hi,
Can you post your button code?

My Guess is the new name is being determined when the button is rendered rather than calculated when the button in clicked. If you move your actions into a macro and invoke them with actions=<<macroname>> on the button it may fix it. Remember the button may have “shortcut” parameters on it like setField but all these can also be done with actions like actionsetfield and actioncreatetiddler.

Thanks for responding.

@pmario see below for the code.

@TW_Tones I understand what you mean but I don’t know what to do about the part that is now wikified. Any suggestions?

Code

I have never used the LetWidget, unusedTitle Macro and ActionCreateTiddlerWidget before. I want to try those because it seems more convenient than my own solutions.
So thank you for your patience.

I have 3 tiddlers for the code.

  1. auto-btn-multi for the actual button
  2. macro-tabs for the macro’s e.g. unusedTitle Macro
  3. button-main-menu to put the above together and showing the button

auto-btn-multi

<$button class=<<class>> tooltip=<<tooltip>>>
<$action-createtiddler 
  	$basetitle=<<new-name>>
  	tags=<<new-tag>>
		caption=<<caption>>
		/>
<$action-createtiddler 
  	$basetitle=<<new-name-1>>
  	tags=<<new-tag-1>>
		caption=<<caption-1>>
		sort=<<sort-1>>
		/>
<$action-createtiddler 
  	$basetitle=<<new-name-2>>
  	tags=<<new-tag-2>>
		caption=<<caption-2>>
		sort=<<sort-2>>
		/>
<<actions>>
<<btn-txt>></$button>

macro-tabs

\define page-name()
<<unusedtitle baseName:page separator:"-" template:"$basename$$separator$$count:5$">>
\end

\define tab-name(name-suf)
<<unusedtitle baseName:$name-suf$ separator:"-" template:"$basename$$separator$$count:5$">>
\end

\define tab-tag-1(tab-suf)
pt/$tab-suf$
\end

\define tab-tags(tag-no)
<<page-name>> pt/tab <<tag-$tag-no$>>
\end

button-main-menu

<$wikify name="new-name" text=<<page-name>>>
<$wikify name="new-name-1" text=<<tab-name tab-inf>>>
<$wikify name="new-name-2" text=<<tab-name tab-lnk>>>
<$wikify name="new-tag-1" text=<<tab-tags 1>>>
<$wikify name="new-tag-2" text=<<tab-tags 2>>>
<$let 

new-name=<<new-name>>
new-tag="page"
caption="change the caption to something meaningful"
btn-txt="NEW PAGE"


new-name-1=<<new-name-1>>
tag-1=<<tab-tag-1 tab-inf>>
new-tag-1=<<new-tag-1>>
caption-1="<<tsl tab-inf>>"
sort-1="1"


new-name-2=<<new-name-2>>
tag-2=<<tab-tag-1 tab-lnk>>
new-tag-2=<<new-tag-2>>
caption-2="<<tsl tab-lnk>>"
sort-2="2"
>

<$transclude tiddler="auto-btn-multi"/>

</$let>
</$wikify></$wikify></$wikify></$wikify></$wikify>

In your code I don’t understand the use of <<actions>>. However here is what I was suggesting;

\define tri-tiddler-create-actions()
<$action-createtiddler 
  	$basetitle=<<new-name>>
  	tags=<<new-tag>>
		caption=<<caption>>
		/>
<$action-createtiddler 
  	$basetitle=<<new-name-1>>
  	tags=<<new-tag-1>>
		caption=<<caption-1>>
		sort=<<sort-1>>
		/>
<$action-createtiddler 
  	$basetitle=<<new-name-2>>
  	tags=<<new-tag-2>>
		caption=<<caption-2>>
		sort=<<sort-2>>
		/>
\end

Then reference this in the button
<$button class=<<class>> tooltip=<<tooltip>> actions=<<tri-tiddler-create-actions>> >

  • Removing the actions from inside the button.
  • I understood from others that this was the way to have the actions “refreshed on click”. I am confident but not certain of this.

By the way - when you provide a $basetitle the resulting tiddler is effectively generated as an unused title. Within the Create tiddler widget you use <<createTiddler-title>> to retrieve the resulting tiddler title with its increment if relevant eg ‘New Tiddler 2’, if “New Tiddler” and “New Tiddler 1” already exist.

  • So Construct the New titles “base title” in the Create tiddler widget and no need to use the untitled macro.

@TW_Tones Yeah that works, thanks !

The 2nd and 3rd tiddler are now used as tabs for the 1st created tiddler. That’s why I am tagging them with the title of the first.

like this: new-tag-1=<<new-name>> and new-tag-2=<<new-name>>
where <<new-name>> is the title of the first tiddler.

However I would also like to add an additional tag to those “tab tiddlers” e.g. extra-tag. But I don’t know how to do this.
The problem being that a macro outside of the button doesn’t refresh on consecutive runs.

Any ideas how to construct adding 2 tags to the “tab tiddlers” ?





  • I am using the unusedTitle Macro because it gives the ability for templating the title. I don’t know if/how that can be done with the $basetitle in the ActionCreateTiddlerWidget.
  • In the current situation the macro is used to supply the tiddler name as a variable in the let widget.

You must either set all tags at once with tags="tagname1 tagname2" inside the create new tiddler parameters

  • One trick here is using a filtered transclusion tags={{{ filter }}} where the filter results in the tags field, with its multiple tags.

or use one or more
<$action-sendmessage $message=" tm-add-tag" $param="tagname"/>

  • Note your code needs to be wrapped in the <$fieldmangler> code </$fieldmangler> widget.

You can also use the ActionListopsWidget on any field including the tags field but that may be more complex than need be.

In the ActionCreateTiddlerWidget it will ensure its a unique name by adding a number at the end, just like the standard new tiddler button, however you can’t set the “count” field places to be zero filled. Of course you decide what the base title is so you can include a separator in it eg $basetitle="$name-suf$ - "

  • I’m unable to use that due to the macro.
  • I’ve tried this solution already but the <$fieldmangler> needs to know the tiddler it will be operating on. Since I have 2 tiddlers I don’t know how to do that.
  • The $basetitle seems to always add in a space character. I 'd rather not have those in my titles. Hence my choice.
  • I totally forgot about this one. Excellent !

And once again, you’re continued help and support are immensely appreciated. Many thanks !

I don’t understand this, my answer was very general.

  • Sure but when facing problems its worth taking the almost good enough approach first. Then asking for help you can give the community working code.