[TW5] Concatenate two or more fields for title of new tiddler?

983 views
Skip to first unread message

Gordan Nia

unread,
May 8, 2017, 8:40:40 AM5/8/17
to TiddlyWiki
It should be trivial, but I can't find a solution:

... to concatenate two or more fields to use them in title of new tiddler created by button, e.g:


<$button>
<$action-sendmessage $message="tm-new-tiddler"

title="{{!!date}} - {{!!text}}"

/>
New Tiddler
</$button>



How?

Thnx!

Mark S.

unread,
May 8, 2017, 10:37:40 AM5/8/17
to TiddlyWiki

Whenever you're thinking of concatenating transclusions from fields or tiddlers, you're probably going to need a macro. Technically all that TW5 macros actually do is concatenate/substitute text. There are different ways of doing this. Sometimes you might set a local variable. In this case I moved all your code into a macrocall and then call it with the MacroCall widget, which can accept and pass the field values you want to the macro.
 
Note, you can't use "text" as a field in this context, because the "text" field is already used as the name for the contents of the current tiddler. This causes a self-referential loop and crashes the TW and, in my case, the entire browser. Besides, you want to use the text to form a single-line title. I created a "text2" field in which to put the text in the example below. You could, if you wanted, refer to the text field of a different tiddler.

HTH
Mark

\define myway(par1 par2)
<$button>
<$action-sendmessage $message="tm-new-tiddler"

title
="$par1$ - $par2$"

/>
New Tiddler
</$button>
\end
<$macrocall $name="myway" par1={{!!date}} par2={{!!text2}}/
>

Gordan Nia

unread,
May 8, 2017, 6:12:15 PM5/8/17
to tiddl...@googlegroups.com
Thanks for the comprehensive answer, now I have a much clearer understanding of TW concept. I was hoping that would be much simpler, but in the end I concluded that I had to solve it in a similar way, for example:


\define Concatenate()
$
(first)$ - $(second)$
\end

...
<$set name=first value={{!!date}}>
<$set name=second value={{!!othertxt}}>

<<Concatenate>>



... but, I think that I will use your way...
Thnx.
Gordan


Mat

unread,
May 8, 2017, 11:22:56 PM5/8/17
to TiddlyWiki
Hi Gordan

IMO the following is more understandable


\define concatenate() {{!!date}} - {{!!othertxt}}

<$wikify name="newtitle" text=<<concatenate>> >
<
$button>
 
<$action-sendmessage $message="tm-new-tiddler" title=<<newtitle>>  />
  New Tiddler
</$button>
</$wikify>

The wikify can optionally be outside the button or inside.

<:-)

Gordan Nia

unread,
May 9, 2017, 3:23:33 AM5/9/17
to TiddlyWiki

Thanks for another solution! Frankly, I've never used WikifyWidget and I'm not quite sure about its use, although I've read the WikifyWidget introduction. As far as I understand, it seems to me that WikifyWidget is used to save some textual content in the variable, or?

Mat

unread,
May 9, 2017, 8:31:54 AM5/9/17
to TiddlyWiki
As I understand it, one can say It "evaluates" the text and saves the result. ("Text" here refers to the input to the WikifyWidget, not to the tiddlers text field)

My typical scenaro is trying to do something with e.g the SetWidget only to literally (and annoyingly) get, say, {{!!title}} when I wanted the evaluated result, i.e the actual title. So the WikifyWidget stores the evaluated ("wikified") result in my variable .

<:-)

Khalfani Wadlington

unread,
Feb 7, 2020, 11:50:20 AM2/7/20
to TiddlyWiki
If anyone wants to use multiple line specify 'html' output and use <br> inplace of a line break.

<$wikify  name="mulitLineText" output=html text="line1 <<now>>  <br> line2 <<now>>">
<<mulitLineText>>

Which evaluates to 

line1 10:48, 7th February 2020
line2 10:48, 7th February 2020
Reply all
Reply to author
Forward
0 new messages