Problem with new tiddler button

Hello everyone.

I’m looking for a way to write the code to create a tiddler with a series of features using a button. I have it more or less defined, but there’s one thing I can’t get to work.

When creating the tiddler, I want the “text” field to already have some things filled in. Specifically, when the tiddler is created, the body text would show something like: “Note created on June 25, 2025.” But not as a reference to a field, but as something that is added to the tiddler upon creation.

This is the code I’m using:

<$button>
  Rapid Note
<$set name="date" value=<<now "DD de MMMM de YYYY">> >
  <$action-sendmessage $message="tm-new-tiddler"
    title=<<now "RapidNot-YYYY0MM0DD0hh0mm0ss0XXX">>
    tags="NRap"
    text="""Note created the {{{ [<date>] }}}:

"""
    caption=""
    icon="$:/core/images/list"
    color="blue"/>

</$set>
</$button>

Thanks in advance.

Perhaps something like this:

\function newline() [charcode[10]]

<$button>
  Rapid Note
<$set name="date" value=<<now "DD de MMMM de YYYY">> >
  <$action-sendmessage $message="tm-new-tiddler"
    title=<<now "RapidNot-YYYY0MM0DD0hh0mm0ss0XXX">>
    tags="NRap"
    text={{{ [[Note created the ]] [<date>] [<newline>] +[join[]] }}}:
    caption=""
    icon="$:/core/images/list"
    color="blue"/>
</$set>
</$button>

I think when the tiddler is saved, any trailing extra blank lines might be removed from the text field, although I don’t know details. In any case, adding multiple [<newline>]'s doesn’t seem to do anything.

Update: removed extra bracket Eric pointed out.

1 Like

Try changing the text param value to this:

text={{{ [[Note created the ]] [<now "DD de MMM de YYYY">] [[:]] [charcode[10],[10]] +[join[]] }}}

Notes:

  • The now macro is invoked directly in the "filtered transclusion " (tripled curly braces). This eliminates the need for a separate $set widget.
  • The literal text preceding the formatted date (and the colon following the date) are specified as literal text filter runs (enclosed in doubled square brackets).
  • The TWO newlines (ASCII code=10) are generated using the charcode filter operator, which accepts a variable number of parameters to specify each desired character code.
  • These individual filter runs are then assembled into a single value using the +[join[]] at the end.

Also note that there is no “MMMM” date format code. The correct format code uses “MMM” for full month name, or “mmm” for abbreviated month name.

@Scott_Sauyet… Your similar solution has an extra closing square bracket on the [<newline>]] filter run. In addition, if you want to have TWO newlines specified using [<newline>], you would need to precede them with = to prevent “de-duplication” of the repeated filter values, like this:

... =[<newline>] =[<newline>] ...

enjoy,
-e

3 Likes

Hello.

I create new tiddler with a button where the content in that new tiddler comes from a template:
The $param="$:/ReE/Meetings/Meeting_Template" refers to the template.

\define newHereButton()
<$button class=<<tv-config-toolbar-class>> tooltip="take Minutes here">
<$action-sendmessage
  $message="tm-new-tiddler"
  $param="$:/ReE/Meetings/Meeting_Template"
  title=<<now "[UTC]YYYY-0MM-0DD - Meeting Title">>
  tags=<<meetingtag>>
  color=#0000ff
/>
1 Like

Oh, much nicer than mine!

That’s what I get for editing and posting without retesting! Fixed.

Ah, yes, of course! Thank you!

2 Likes

Thanks everyone for your help. I’ve finally achieved what I wanted to do.

But there are a couple of things I’m not sure about:
1: In Scot’s model, this part of the code \function newline() [charcode[10]] is visible in the tiddler where I put it. I don’t know how to make it invisible when I exit the editing process.

2: I’ve tried replicating Scott and Eric’s model to create a diagram with several line breaks, but I haven’t been able to. This is what I want to appear in the created tiddler.


Note created on ...

!!!Content:

!!!Actions:

---
<<<
''Context:''
<<<

And this is the code I used, but it doesn’t work.

<$button>
 Note
  <$action-sendmessage $message="tm-new-tiddler"
    title=<<now "Rapid_Not-YYYY0MM0DD0hh0mm0ss0XXX">>
    tags="NRap"
    text={{{ [[Note created the ]] [<now "DD of MM dof YYYY">] [charcode[10],[10]] [[''Content'']] [charcode[10],[10]] [[''Acctions'']] [charcode[10],[10]] [[---]] [charcode[10],[10]] [[<<<]] [charcode[10]][[''Contex'': ]] [charcode[10]] [[<<<]] +[join[]] }}}
    caption=""
    icon="$:/core/images/list"
    color="blue"/>
</$button>

I know I can do it easily from a template, but I would like to know if there is another way to do it.

Best regards.

Make sure the \function declaration occurs at the start of the tiddler (i.e, before any content to be displayed).

The above filter is composed of a sequence of “filter runs”. By default, the TWCore filter processing does a “de-duplication” of identical filter runs, so only the last of the identical filter runs is actually included in the result. In your filter, you have multiple instances of [charcode[10],[10]] and [charcode[10]], so only the last instance of each of those filter runs is included in the result.

Fortunately, there is a way to explicitly tell the TWCore filter processing not to remove duplicate filter runs, by preceding each duplicate filter run with =. Thus, your filter syntax should be something like this:

text={{{ [[Note created on ]] [<now "DD of MMM of YYYY">]
   =[charcode[10],[10]] [[!!!Content:]]
   =[charcode[10],[10]] [[!!!Actions:]]
   =[charcode[10],[10]] [[---]]
   =[charcode[10]] =[[<<<]] =[charcode[10]] [[''Context:'']] =[charcode[10]] =[[<<<]]
   +[join[]]
}}}

Let me know how it goes…

enjoy,
-e

2 Likes

And more generally, make sure that all Pragmas (identified in TW by the leading backslash) appear at the beginning of the tiddler, before any regular content.

2 Likes

Thanks for the explanation, Eric.

But there’s something I don’t quite understand: if I don’t add \function newline() [charcode[10]] at the beginning of the tiddler and instead add the following code:

<$button>
Quick Note
<$action-sendmessage $message="tm-new-tiddler"
title=<<now "Rapid_Not-YYYY0MM0DD0hh0mm0ss0XXX">>
tags="Rap_Not"
text={{{ [[__]] [[Note created on ]] [<now "DD of MMM of YYYY at 0hh:0mm">] =[[__]] =[charcode[10],[10]] +[join[]] }}}
caption=""
icon="$:/core/images/list"
color="blue"/>
</$button>

it works fine.

I understand that if I add the function, then I would have to add the code like this, like Scott did. Like this:

\function newline() [charcode[10]]
<$button>
Quick Note
<$action-sendmessage $message="tm-new-tiddler"
title=<<now "Rapid_Not-YYYY0MM0DD0hh0mm0ss0XXX">>
tags="Rap_Not"
text={{{ [[__]] [[Note created on ]] [<now "DD of MMM of YYYY at 0hh:0mm">] =[[__]] [<newline>] +[join[]] }}}
caption=""
icon="$:/core/images/list"
color="blue"/>
</$button>

Or am I missing something?

Apologies in advance if what I’m asking is obvious, but I understand just enough programming…

Eric and I used two different approaches to handling newlines… Eric’s is perhaps simpler; mine is more explicit. But we generally wouldn’t combine them. There’s no need to mix and match.

Eric uses [charcode[10]] wherever a new line needed. I define a newline variable, which I then use as <newline> wherever I need one. I like the explicit name. But if you’re using Eric’s technique, my function declaration is useless.

There is actually a third technique. In many places, you can just use an actual newline. You don’t see much of this since charcode was created. But it would look something like this (untested) version:

text={{{ [[Note created on ]] [<now "DD of MMM of YYYY">] =[

] [[!!!Content:]] =[

] [[!!!Actions:]] =[

] [[---]] =[
] =[[<<<]] =[
] [[''Context:'']] =[
] =[[<<<]]
   +[join[]]
}}}

It’s pretty ugly and easy to mess up, but it works in many places.

1 Like

Thanks, Scott.
Now it all makes sense.

Thanks again.