Special Copy of Title to Description Field

110 views
Skip to first unread message

History Buff

unread,
Jan 8, 2021, 7:06:27 PM1/8/21
to TiddlyWiki
In an effort to take advantage of the tree macro, I want to create a button to copy the Title of a filtered set of tiddlers to the description field in a certain way. For instance, if the title of the tiddler is Atchison, Topeka & Santa Fe Railway, I'd like the description field to look like: Railroad-A-Atc-Atchison, Topeka & Santa Fe Railway.

The copying of the title to the description field with the extra text I think is relatively easy. However, I'm having trouble figuring out how to extract the first character and the first three characters from the title. Any suggestions?

Many thanks in advance!

Eric Shulman

unread,
Jan 8, 2021, 8:01:50 PM1/8/21
to TiddlyWiki
On Friday, January 8, 2021 at 4:06:27 PM UTC-8 History Buff wrote:
The copying of the title to the description field with the extra text I think is relatively easy. However, I'm having trouble figuring out how to extract the first character and the first three characters from the title. Any suggestions?

Note: the TWCore "toc" macros use the "caption" field (not "description") to define the text to display for each toc entry.

<$button> set captions
  <$list filter="...">
      <$action-setfield caption={{{ [[Railroad]] [{!!title}split[]first[]] [{!!title}split[]first[3]join[]] [{!!title}] +[join[-]] }}} />
   </$list>
</$button>

Notes:
* The $list filter is whatever you want to use to select your desired "set of tiddlers".
* For each matching tiddler, the caption field value is constructed using 5 filter "runs" within a "filtered transclusion" syntax: {{{ ... }}}
* [[Railroad]] is literal text
* [{!!title}split[]first[]] extracts the first character from the title
* [{!!title}split[]first[3]join[]] extracts the first 3 characters from the title
* [{!!title}] is the full title text
* +[join[-]] combines the previous 4 parts with "-" in between each part

The result is a single text value, e.g., "Railroad-A-Atc-Atchison, Topeka & Santa Fe Railway"
which is then stored in the "caption" field of the current tiddler.

enjoy,
-e

History Buff

unread,
Jan 9, 2021, 4:09:02 PM1/9/21
to TiddlyWiki
Thanks Eric. That looks just like what I need. I saw the first operator, but thought it returned the entire title of the first item in the list. Now I know better.

As far as using the description field goes, I have a custom tree macro that uses the description field instead of the caption field. I did that (with help) because I needed to use the caption field separately.

I'll let you know how it goes.

Eric Shulman

unread,
Jan 9, 2021, 4:42:05 PM1/9/21
to TiddlyWiki
On Saturday, January 9, 2021 at 1:09:02 PM UTC-8 History Buff wrote:
I saw the first operator, but thought it returned the entire title of the first item in the list.

It *does* return the title of the first item in the list.  However, in this usage, first[] is preceded by split[] with no parameter value, which chops up the initial title text into single character "titles".  Note also that first[...] accepts a parameter for how many items to return.  Thus, {!!title}split[]first[] returns a one-character "title", while {!!title}split[]first[3]join[] returns a 3-character "title".

-e

History Buff

unread,
Jan 10, 2021, 1:01:48 PM1/10/21
to TiddlyWiki
Ah, that makes perfect sense. Thanks for explaining. That's one of the problems I have with expanding my knowledge of TW. I find it difficult to look beyond the basic uses of the operators and expand my outlook like this. Thanks so much.
Reply all
Reply to author
Forward
0 new messages