How to build a new tiddler title for <$button>

98 views
Skip to first unread message

Mark Hylton

unread,
Jul 31, 2020, 3:41:19 PM7/31/20
to tiddl...@googlegroups.com
How do I programmatically build a string to be used as the title for a new tiddler (<$button> ... $message="tm-new-tiddler" ... title=???)?

I'm trying to use <$button> to start a new tiddler, but I can't get the title set the way I wish. What I want the new tiddler title to be (for instance) is "A1234,Risk (2020-07-27 15:00:00): ", where:

* "A1234": value of storyTiddler's field "projectnumber".
* ",": literal.
* "Risk": literal for the purposes of this discussion (would prefer it to be parameterized somehow eventually).
* " (": literal.
* "2020-07027 15:00:00": from "<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>".
* "): ": literal.

I am currently using (inside <$button>) 'title=<<now "addProjectNumberHere,Risk (YYYY-0MM-0DD 0hh:0mm:0ss): ">>'. (The "addProjectNumberHere" is just a reminder to me to place the project number into the title whenever I add a new risk.)

It seems that I have to execute the "now" macro only when the new tiddler is created, else the date/time will be off. But, I can't concatentate anything on the "title=" line, and attempting to build the "title=" line with a different macro just passes the macro definition characters to the title (no evaluation).

The button is a tiddler titled "buttonNewRisk". That button is transcluded in a tiddler "listProjectRisks". That list is hosted as a tab of the story tiddler "A1234".

Tiddler text for the button to generate a new Risk tiddler follows:

\define projnum()
<$view tiddler=<<storyTiddler>> field=projectnumber/>
\end
\define taglist()
<<projnum>> risk
\end
\define titlemaker()
<<projnum>>,Risk (<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>): THIS DOESN'T WORK WHEN CALLED AS A MACRO ON THE "title=" LINE BELOW
\end

\define buttonnewrisk()
   <$wikify name="newtags" text=<<taglist>> >
   <$wikify name="newprojnum" text=<<projnum>> >
      <$button>

         New project risk entry
         <$set name="newtext" value={{creationtemplateRisk}} >
            <$action-sendmessage
               $message="tm-new-tiddler"
               title=<<now "addProjectNumberHere,Risk (YYYY-0MM-0DD 0hh:0mm:0ss): ">>
               tags=<<newtags>>
               text=<<newtext>>
               projectnumber=<<newprojnum>>
            />
         </$set>
      </$button>
   </$wikify>
   </$wikify>
\end


Need to document a new project risk? Click this [[button|buttonNewRisk]] and, with this [[template|creationtemplateRisk]], a risk tiddler will be created and tagged with ''risk'' and with ''<<projnum>>'': <<buttonnewrisk>>


Mark Hylton

unread,
Jul 31, 2020, 3:54:52 PM7/31/20
to TiddlyWiki
Using TW5: v5.1.21, but willing to upgrade if needed.

Mark S.

unread,
Jul 31, 2020, 5:02:54 PM7/31/20
to TiddlyWiki

I've left out here the parts where you're other tiddlers and templates that I don't have access to. But this should get you started.



<$button> Make it
<$vars tim=<
<now "YYYY-0MM-0DD 0hh:0mm:0ss">>  newtext="my new text" newprojnum="7689" >
   <$action-sendmessage
               $message="tm-new-tiddler"
               title={{{ [{!!projectnumber}addsuffix[,Risk (]addsuffix
<tim>addsuffix[)]] }}}
               tags={{{ [{!!projnum}append[ risk]] }}}
               text=<
<newtext>>
               projectnumber=<
<newprojnum>>
   />

</$vars>
</$button>


Eric Shulman

unread,
Jul 31, 2020, 5:35:09 PM7/31/20
to tiddl...@googlegroups.com
On Friday, July 31, 2020 at 12:41:19 PM UTC-7, Mark Hylton wrote:
How do I programmatically build a string to be used as the title for a new tiddler (<$button> ... $message="tm-new-tiddler" ... title=???)?
I'm trying to use <$button> to start a new tiddler, but I can't get the title set the way I wish. What I want the new tiddler title to be (for instance) is "A1234,Risk (2020-07-27 15:00:00): ", where:

Here's my solution:
\define newRisk_button() <$button actions=<<newRisk_actions>>> New project risk entry </$button>

\define newRisk_actions()
<$vars
   projnum={{{ [<storyTiddler>get[projectnumber]] }}}
   time=<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>
>
<$action-sendmessage $message="tm-new-tiddler"
   title={{{ [<projnum>addsuffix[,Risk (]addsuffix<time>addsuffix[)]] }}}
   tags={{{ [<projnum>addsuffix[ risk]] }}}
   text={{creationtemplateRisk}}
   projectnumber=<<projnum>>
/
>
</$vars>

\end

Need to document a new project risk?
Click this button: <<newRisk_button>> to create a new risk tiddler with this [[template|creationtemplateRisk]]
and tagged with <$macrocall $name="tag" tag={{{ [<storyTiddler>get[projectnumber]] }}} /
> and <<tag risk>>

Notes:
* newRisk_button() macro outputs a $button widget (note the *single-line* macro definition omits the \end)
* $button uses the actions="..." parameter to defer all button processing until the button is pressed
* this allows the <<now>> macro below to get the current datetime value at the time the button is pressed

* newRisk_actions() macro is invoked when the $button is pressed
* $vars uses an inline filter to get the projnum value from the current storyTiddler's "projectnumber" field
* it also get the current datetime value using the <<now>> macro
* $action-sendmessage triggers tm-new-tiddler to create a new tiddler
* the title param uses an inline filter to construct the new title from the projnum and datetime
* the tags param uses an inline filter to construct the new tags from the projnum and "risk"
* the text param fetches the template contents
* the projectnumber param adds a field with the value of the projnum

Then:
the text of the tiddler shows the newRisk_button and a link to the template
along with "tag pills" for the current storyTiddler's project number and the "risk" tag.

enjoy,
-e

TW Tones

unread,
Jul 31, 2020, 7:48:58 PM7/31/20
to TiddlyWiki
Mark,

Just a coding opinion here, if you are going to the effort of having your own new tiddler button, why not move such values into fields?, and let titles be descriptive.

Without putting the argument again, I have a number of times in the forum, using compound titles as an organising method is a recipe for later issues. 

There are some rare cases where programaticaly generated titles are needed, but even then they should not be compound titles, why embed details inside a title when you can maintain that information independently in fields?

Regards
Tony

Mark Hylton

unread,
Jul 31, 2020, 10:40:45 PM7/31/20
to TiddlyWiki
Mark,

Thank you for taking the time to respond. I tweaked your solution a bit, and got it mostly working. I was not familiar with the triple braces syntax, or the "addsuffix" and "append" options; this was great to learn about, thank you!

The biggest unresolved issue I found was that the "now" macro isn't being evaluated when the button is pressed. I suspect it is evaluated when the button definition is evaluated, not when the button click is evaluated. In one of my tests I found that the time used in the tiddler title was a couple minutes old.

FYI, I found that Eric Shulman's solution (below) worked well and managed the "now" macro in a fashion that evaluated at button click time. FYI.

Thank you again!

My best,

Mark

Mark Hylton

unread,
Jul 31, 2020, 10:41:20 PM7/31/20
to tiddl...@googlegroups.com
Eric,

Thank you for your reply, especially for the comments on how it works. And, it works perfectly.

And, I got to learn several new things as a result. Defering variable evaluation until button press was what I was needing, but wasn't aware of using actions. Thank you much, good sir.

My best,

Mark

Mark Hylton

unread,
Jul 31, 2020, 10:42:00 PM7/31/20
to TiddlyWiki

TW,

Thank you for your 1000-foot view of my problem, and you are exactly right.

In my defense, this is something I've been tweaking for a number of years, changing it and improving it when my job needs changed, and learning TW as I went. It is overdue for being refactored now that I know more ... but I haven't wanted to spend the time. But it'll get done.

Also, the tidder titles have all that information so that a (relatively simple) filtered list would alphabetize well, as that was the first way I learned for how to get a list of what I wanted. I've been putting the information into tags, and later into fields, but during my initial design I didn't know when to use tags vs. fields, or how to use fields, and I'm still not sure how to filter with fields (but I assume it is possible).

Thanks again!

My best,

Mark
Reply all
Reply to author
Forward
0 new messages