[Adding / concatenating / joining / merging] several variables in one single output or text

137 views
Skip to first unread message

Fidel N

unread,
Oct 14, 2016, 6:41:38 AM10/14/16
to tiddl...@googlegroups.com
Hi all:
I had a hard time finding this either in tiddlywiki documentation or this group, so Im posting this in case its helpful or someone decides to post it to the main Tiddlywiki documentation.

I wanted to dynamically create a new tiddler which text should come from a list of combo-boxes, but I couldnt find the way to mix all the variables into the resulting tiddliwiky tiddler.

I asked a very skilled friend of mine and he came with this solution that I would have never imagined or found:

<$select field='letter'>
<option><$action-setfield letter/>A</option>
<option><$action-setfield letter/>B</option>
<option><$action-setfield letter/>C</option>
</$select>

<$select field='number'>
<option><$action-setfield number/>1</option>
<option><$action-setfield number/>2</option>
<option><$action-setfield number/>3</option>
</$select>

<$button>
Something
<$action-setfield $tiddler="Mixing variables examples" tags='mixed_vars' aaa={{!!number}} bbb={{!!letter}} $value="{{!!aaa}} {{!!bbb}}"/>
</$button>


The key is the following part, in which current tiddler variables are stored into the ones that are evaluated again from within the new tiddler:
aaa={{!!number}} bbb={{!!letter}}

This solution is super simple, fast, and requires no macros.

Best regards!



Fidel N

unread,
Oct 14, 2016, 1:17:11 PM10/14/16
to TiddlyWiki
After a while I realized the new tiddlers are actually being created with a variable inside called "aaa" and another "bbb" and the text is "{{!!aaa}} {{!!bbb}}" and it renders good but its not creating the tiddler with the evaluated text.

Did someone manage to create a new tiddler with the text inside several variables of the current tiddler?
I have tried with macros and all sort of variable combinations but in the end the text within the new tiddler is always "{{!!aaa}} {{!!bbb}}", never the content of those variables :(

Mark S.

unread,
Oct 14, 2016, 1:35:39 PM10/14/16
to TiddlyWiki
You don't specify a field in your actionsetfield widget, but I'm guessing that you're trying to change the tags?

My recipe is to use a macro for concatenation. Since using a macro with parameter tends to break it I always put the intended concatenation items into variables. Then the macro concatenates the list. Here's some code:
 

\define concat() [[$(ltr)$]] [[$(num)$]]
<$select field='letter'>
<option>A</option>
<option>B</
option>
<option>C</option>
</
$select>

<$select field='number'>
<option>1</option>
<option>2</
option>
<option>3</option>
</
$select>

<$vars ltr={{!!letter}} num={{!!number}}>
<$button>
Something
<$action-setfield $tiddler="Mixing variables examples" $field="tags"  $value=<<concat>>/>
</
$button>
</$vars>

Fidel N

unread,
Oct 14, 2016, 1:50:09 PM10/14/16
to TiddlyWiki
Wow thank you Mark... yes, I wanted it for text but already tested it with both tags and text and works just great...
I miss those kind of examples (how to join two variables) on the Tiddlywiki main documentation though :)

Thanks again!

Tobias Beer

unread,
Oct 14, 2016, 2:46:42 PM10/14/16
to tiddl...@googlegroups.com
Hi Fidel,

For your most sophisticated concatenation requirements, take a look at:


Best wishes,

Tobias. 

Fidel N

unread,
Oct 14, 2016, 3:01:58 PM10/14/16
to TiddlyWiki
Awesome Tobias, thanks!!
I have been using TiddlyWiki for a few days now and the more I know the more I want to know!! :D
Reply all
Reply to author
Forward
0 new messages