Unusedtitle Macro and Text Substitution

I have a procedure called create-item. It is used to create new tiddler with specific fields, etc.

\whitespace trim
\procedure full-path() $:/state
\function base-title() [<full-path>] [<type>] [<title>] :and[join[/]]

\procedure create-item(btncaption:"new item", type, title, tags)
<$button> <<btncaption>>
	<$action-sendmessage $message="tm-new-tiddler" title=`${[<unusedtitle $(base-title)$>]}$` tags=<<tags>> />
</$button>
\end


<<create-item "My New Test" type:"macros" title:"mac" tags:"$:/tags/Macro">>

But the unusedtitle does not work correctly and does not increment the title. It always create a new tiddler with

$:/state/macros/mac

Is this a bug?

From the docs:

Filter expression placeholders are substituted before variable placeholders, allowing for further variable substitution in their returned value.

Your code assumes that the variable will be substituted before the filter expression is evaluated.

1 Like

Thank you Saq,
So do I have to go through $wikify? I try to not use macro!

I think @pmario has given a good example here:

In the above answer, @pmario used $wikify. I tried to avoid them (macro and $wikify) and I arrived to this ugly but working solution:

\whitespace trim
\procedure full-path() $:/state


\procedure create-item(btncaption:"new item", type, title, tags)
<$let base-title= {{{ [<full-path>] [<type>] [<title>] :and[join[/]]      }}}
      new-title=  {{{ "[<unusedtitle $(base-title)$>]" :and[substitute[]] }}} >
<$button> <<btncaption>>
	<$action-sendmessage $message="tm-new-tiddler" title={{{ [subfilter<new-title>] }}}  tags=<<tags>> />
</$button>
</$let>
\end


<<create-item "My New Test" type:"macros" title:"mac" tags:"$:/tags/Macro">>

Any simpler, shorter solution not using $wikify?