How to concatenate <<now ...> and a tiddler field value for use as a new tiddler title

123 views
Skip to first unread message

markh...@gmail.com

unread,
Feb 21, 2018, 11:17:49 PM2/21/18
to TiddlyWiki
I've two things I want to do:

1) I want to use the current date/time as part of a concatenated string for a new tiddler title.
2) I want to use the value of a field from the host tiddler as part of a concatentated string for a new tiddler title.
3) I want to use 1) and 2) at the same time for the same new tiddler.

E.g.:

A host tiddler has a field "projectnumber" and that tiddler also hosts a transcluded tiddler "newProjectEntry". "newProjectEntry" holds <$button>
code to create a new tiddler. Clicking the newProjectEntry button from the host tiddler is intended to generate a new tiddler with a title "2018-02-01 09:57:04, 12345, Project entry:" where:
  1. "2018-02-01 09:57:04" is the value from <<now ...>> when the button is clicked.
    1. Issue 1: I can get a date/time string, but it is the date/time AT THE TIME that tiddler "newProjectEntry" is rendered in the host tiddler, not at the time the button was pressed.
    2. Issue 2: Otherwise, I get the text string "<<now ...>>" instead of the rendered version for <<now ...>>.
    3. Issue 3. Or otherwise, I get the proper date/time, but am unable to concatenate a looked-up project number.
  2. "12345" is the value of host tiddler's projectnumber field.
    1. Issue 1: I can get the host tidder's title ("<<storyTiddler>>"), but the construct "<<storyTiddler!!projectnumber>>" doesn't seem to work.
  3. "Project entry:" (and the other spaces and commas) are text literals.
    1. No issues here. I've mostly had sufficient guidance on how to concatenate things. So far. I think.

What I've written:

Tiddler 1 fields:
Title:hostTiddler
projectnumber:12345
Text:{{newProjectEntryPB}}

Tiddler 2 fields:
Title:newProjectEntryPB
Text:\define projecttitle() $(todaynow)$, $(projectnum)$, Project entry:

<$set name="todaynow" value=<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>>
<$set name="projectnum" value={{<<storyTiddler!!projectnumber>>}}>

Need a new project entry? Click this button and a project tiddler will be created:
<$button>
      New project entry
      <$action-sendmessage
         $message="tm-new-tiddler"
         title=<<projecttitle>>
      />
</$button>

</$set>

When the button is clicked from within hostTiddler, it generates a new tiddler with the title:
2018-02-21 18:36:34, , Project entry:

1) Issue: The date/time is not current with the button press.
2) Issue: Unable to get the project number value from the host tiddler.

Thanks much for your help!

Mark Hylton

Stephan Hradek

unread,
Feb 22, 2018, 4:44:16 AM2/22/18
to tiddl...@googlegroups.com
Before taking too many steps and making it overly complicated: Have you thought about utilising a Journal tiddler?

Take a look at "Making a custom journal button"

Michael Wiktowy

unread,
Feb 22, 2018, 9:09:26 AM2/22/18
to TiddlyWiki
Look up <$wikify>. It is like <$set> but it renders/evaluates the value to the variable rather than just storing it for further rendering in another context (or not rendering like in one of your cases). So you get to choose where the value gets set in stone. I had a similar issue recently and that is how I got around it.

/Mike

Stephan Hradek

unread,
Feb 22, 2018, 9:15:30 AM2/22/18
to tiddl...@googlegroups.com
A quick & Dirty example.


tiddler: New Button
projecttitle (required field): "Project #00001, YYYY-0MM-0DD 0hh:0mm:0ss"
text:
\define journalButton()
<$button tooltip={{$:/language/Buttons/NewJournal/Hint}} aria-label={{$:/language/Buttons/NewJournal/Caption}} class=<<tv-config-toolbar-class>>>
<$action-sendmessage $message="tm-new-tiddler" title=<<now "$(journalTitleTemplate)$">> tags="$(journalTags)$" text="$(journalText)$"/>
<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/new-journal-button}}
</$list>
<$list filter="[<tv-config-toolbar-text>prefix[yes]]">
<span class="tc-btn-text"><$text text={{$:/
language/Buttons/NewJournal/Caption}}/></span>
</$list>
<$action-increment $reference="New Project!!projecttitle"/
>
</$button>
\end
<$set name="journalTitleTemplate" value={{New Project!!projecttitle}}>
<$set name="journalTags" value={{$:/
config/NewJournal/Tags}}>
<$set name="journalText" value={{$:/config/NewJournal/Text}}>
<<journalButton>>
</$set></$set></$set>

I took the complete code from the $:/core/ui/Buttons/new-journal tiddler and just changed

"$:/config/NewJournal/Title" to "New Project!!projecttitle"
and added <$action-increment $reference="New Project!!projecttitle"/>
which requires you  to have my action-increment plugin installed

The Projectnumber will increase with every click and the title will be something like "Project #00001, 2018-02-22 13:14:15".

markh...@gmail.com

unread,
Feb 22, 2018, 9:54:47 AM2/22/18
to TiddlyWiki
Good morning, Stephan,

BOTTOM LINE: a journal tiddler will work, I just have to drop the project number requirement in the title. Consider that done. *I still want* (and don't know how) to get a field value from the storyTiddler.

Ever do something because it was the first way you concepted it, only to struggle? And then someone comes along and asks, "why that way, why not another?"? :)

Well ... there's part of your answer. My first thought was to display, as part of the tiddler title, a time/date stamp (keeps titles unique), along with the project number the entry was about, and a bit of text for additional information.

As I learn more about TW filtered lists, the need for the project number in the title diminishes, as long as that project number is available elsewhere in a tiddler for filtering use. And, I can easily include text literals with the time/datestamp tiddler name.

HOWEVER, I still have use cases for getting a field value from a host tiddler (the storyTiddler?) for use in generating a new tiddler. In this case, I want to get the value of the projectnumber field from the host tiddler and put it in a projectnumber field of a new tiddler. I can already do something like this, if 1) the host tiddler's title IS the project number (and nothing else), and 2) I use that title as the value for the new tiddler's projectnumber field. This works, but feels clunky because a title is not the same (conceptually) as a project number, even though they are the same (textually) in this particular use case.

While a tag seems to be the best way to provide inclusion of a tiddler into a larger set, there might be multiple tags, and how am I to know which one is a project number and which ones are not? A projectnumber field seems to be a better way to denote inclusion into a project set, in this case. So, I want to use a field for a project number, and not rely solely on tags to contain the project number. (This opens up the question of best uses for tags versus fields.)

In any case, thank you for looking at this and asking your question. A second look from a different point of view is frequently valuable, and it gets me out of a thinking rut I didn't realize I was in.

Thanks again!

~Mark

Stephan Hradek

unread,
Feb 22, 2018, 11:20:55 AM2/22/18
to TiddlyWiki
Can you test, what you attempted on tiddlywiki.com and post all the tiddlers here so that I can see and aybe correct?

For your previous example, it is an easy fix:


Tiddler 1 fields:
Title:hostTiddler
projectnumber:12345
Text:{{||newProjectEntryPB}}

Tiddler 2 fields:
Title:newProjectEntryPB
Text:\define projecttitle() $(todaynow)$, $(projectnum)$, Project entry:

<$set name="todaynow" value=<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>>
<$set name="projectnum" value={{!!projectnumber}}>


Need a new project entry? Click this button and a project tiddler will be created:
<$button>
      New project entry
      <$action-sendmessage
         $message="tm-new-tiddler"
         title=<<projecttitle>>
      />
</$button>

</$set>

Of course this doesn't fix the timestamp, but the projectnumber is in

Stephan Hradek

unread,
Feb 22, 2018, 12:31:41 PM2/22/18
to TiddlyWiki
Of course this doesn't fix the timestamp, but the projectnumber is in.

Ah! And for an auto-incremented projectnumber you saw my "Quick & Dirty" example above?

markh...@gmail.com

unread,
Feb 22, 2018, 1:28:24 PM2/22/18
to TiddlyWiki
Stephan,

BOTTOM LINE: Things are now working as I need them to be working. Project number in the title was dropped. "Inheriting" a field value (the project number, in this case) in a new tiddler was added.

I think it is more important to have the date/timestamp in the title (to help keep titles unique, and to easily organize them by date), than to have the project number in the title. While I would still like the project number there, I'm dropping this requirement. Thank you for asking your questions, as they forced me to re-evaluate my true needs.

Being able to "inherit" the project number from the host/parent tiddler when creating a new tiddler is, however, important for other kinds of tiddler organization. You've shown how this can be done; I'll have to research why this works because it emphasizes my lack of understanding of TW and scope of values.

I've chosen to not explore your auto-incrementing project number, but I appreciate the suggestion.

As a result, I've got things working the way I need them to work. At least until I come with a new requirement.

Thanks again!

~Mark

P.S. How are these posts marked as "Complete", so other helpful folks don't have to go through everything just to find out the problem is resolved?

markh...@gmail.com

unread,
Feb 22, 2018, 1:32:08 PM2/22/18
to TiddlyWiki
Mike,

I tried to use <$wikify> ... and couldn't figure out how to use it correctly, so I don't know if it could have worked or not. On the other hand, I've gotten my current problem(s) resolved (see later posts in this thread), so I won't look further into this, for now anyway.

I much appreciate your suggestion and help, however!

Sincerely,

~Mark
Reply all
Reply to author
Forward
0 new messages