Use Unusedtitle-, Now-macro to Dynamically Define a Unique Name to use With ActionCreateTiddlerWidget

It’s a bit tricky since we do have a core <<unusedtitlemacro which has 3 parameters and the first one should be a <<now macro call. Nesting macros is tricky. So in this case the $wikify-widget is a possibility to create some readable code.

  • We use the new text substitution option for widget parameters, to create the unusedtitle-macro-string, that can be wikified by the wikify-widget

  • We start with a function: \function utNow() [<now "YYYY0MM0DD">] to get the <<now macro out fo the way. It will be used by the text-substitution later

  • the text-parameter of the wikify-widget uses 5 elements
    a) macro name … <<unusedtitle
    b) 1st macro param basename:"$(utNow)$"
    c) 2nd macro param separator:"_"
    d) 3rd param template:"$basename$$separator$$count:4$" … to create the title
    e) closing the macro started at a) >>

  • template description can be found at the unusedtitle Macro tiddler

\function utNow() [<now "YYYY0MM0DD">]

\procedure testCreate()
<$wikify name="getTitle"
  text=`<<unusedtitle baseName:"$(utNow)$" separator:"_"
                      template:"$basename$$separator$$count:4$" >>`
>
  <$action-createtiddler $basetitle=<<getTitle>> />
</$wikify>
\end

<$button actions=<<testCreate>> >
Create Tiddler
</$button>

createtiddler-using-unusedtitle-and-now-macro.json (488 Bytes)

hope that makes sense.
-mario

2 Likes

@stobot … I had to fix a typo in the OP, so the code works as expected. It needs to be baseName: instead of basename in the old code :confused:

@TW_Tones created a different version, which calculates the new title using a wikitext function.

See: Problems setting title of a newly created tiddler - #20 by TW_Tones

\function next-title() [range[1],[99]] +[pad[2]addprefix[-]addprefix<now YYYY0MM0DD>!has[title]] +[first[]]

<$button>
<$action-createtiddler $basetitle={{{ [function[next-title]]  }}} tags="test" text="content">
<$action-navigate $to=<<createTiddler-title>>/>
</$action-createtiddler>
Create Tiddler and Navigate
</$button>

Or

\function next-title() [range[1],[99]] +[pad[2]addprefix[-]addprefix<now YYYY0MM0DD>!has[title]] +[first[]]

<$button>
<$action-createtiddler $basetitle=`${ [function[next-title]]  }$` tags="test" text="content">
<$action-navigate $to=<<createTiddler-title>>/>
Create Tiddler
</$button>
1 Like