Combine tiddlers into one

169 views
Skip to first unread message

Odin

unread,
May 15, 2021, 4:51:07 AMMay 15
to TiddlyWiki
I have a series of notes on a subject I want to archive by putting them into one tiddler, so I can remove the individual tiddlers. I am trying to make a button to do this.

With this filter, it brings the desired effect. If you copy this to tiddlywiki.com, it will combine all tiddlers with the 'About' tag, while keeping their titles to separate them.

<$list filter=[tag[About]]>
<h2> <$transclude tiddler=<<currentTiddler>> field="title" mode="block"/> </h2>
<$transclude tiddler=<<currentTiddler>> field="text" mode="block"/>
</$list>

I tried using this template using the $wikify widget. {{template}} refers to tiddler with the filter above as its text.

<$button>
<$wikify name="selection" text={{template}} mode="block">
 <$action-sendmessage $message="tm-new-tiddler" title="Combined" text=<<selection>>/>
</$wikify>
click here to combine about tiddlers
</$button>

But this gives me javascript errors (Uncaught InvalidCharacterError: Failed to execute 'createElementNS' on 'Document': The qualified name provided ('$element') contains the invalid name-start character '$'.) It also doesn't really copy everything over in the right way, because the wikitext formatting is not applied.

I think I am trying to solve this problem from the wrong angle. I am hoping someone can point me towards the right direction.

kind regards,

Odin

Mohammad Rahmani

unread,
May 15, 2021, 5:14:39 AMMay 15
to tiddl...@googlegroups.com
Odin,
 I have not read your post but search the Forum! There is long thread discussed this and Jed Carty provided
 some good solutions for this!


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/d760d472-00cd-4eb8-8bd0-a01899613a40n%40googlegroups.com.
Message has been deleted

Saq Imtiaz

unread,
May 15, 2021, 5:41:31 AMMay 15
to TiddlyWiki
Below are three different ways to do this using reduce and without wikify. The last one uses a custom filter printf[] that is attached.
Note that you can use a tiddler for your template as well.

#1 - addprefix galore

<$button> save to a single tiddler 
<$vars lb="
"> 
<$action-setfield $tiddler="report" text={{{ [tag[About]] :reduce[get[text]addprefix<lb>addprefix<lb>addprefix{!!title}addprefix[!!]addprefix<lb>addprefix<accumulator>] }}}/> 
</$vars> 
</$button>

#2 - search-replace

<$button> save to a single tiddler 
<$vars template="
!! _TITLE_

_TEXT_
"> 
<$action-setfield $tiddler="report" text={{{ [tag[About]] :reduce[<template>search-replace:gi[_TITLE_],{!!title}search-replace[_TEXT_],{!!text}addprefix<accumulator>] }}}/> 
</$vars> 
</$button>

#3 - printf[]

<$button> save to a single tiddler 
<$vars template="
!! $0$

$1$
"> 
<$action-setfield $tiddler="report" text={{{ [tag[About]] :reduce[<template>printf{!!title},{!!text}addprefix<accumulator>] }}}/> 
</$vars> 
</$button>
$__plugins_sq_filters_filters_printf.js.json

Anjar

unread,
May 15, 2021, 5:46:45 AMMay 15
to TiddlyWiki
Hi,

This would be very easy if we had a general way to hard-replace macros at tiddler save; see https://groups.google.com/g/tiddlywiki/c/crnjiJ4Spq4 (I'm mentioning it here since google groups doesn't show backlinks..)

Best,
Anders

Odin

unread,
May 15, 2021, 5:54:30 AMMay 15
to TiddlyWiki
Thank you Saq for the solutions!! Helps a lot : )

@Mohammed, I did try a search in the TW-scripts. So I think I will add a pull request to include Saq's solutions soon!

Op zaterdag 15 mei 2021 om 11:46:45 UTC+2 schreef Anjar:

TiddlyTweeter

unread,
May 15, 2021, 7:25:51 AMMay 15
to TiddlyWiki
Below are three different ways to do this using reduce and without wikify. The last one uses a custom filter printf[] that is attached.
Note that you can use a tiddler for your template as well....

You are a very clever man! 
A published generic APPEND macro might be an desirable outcome?

It is often, often  requested.

Just a comment, but slightly more serious than usual :-).
TT 

Saq Imtiaz

unread,
May 15, 2021, 7:34:26 AMMay 15
to TiddlyWiki
@TT what form would such a macro take? Just to display combined text, or save it somewhere? And in what format/structure?

If the majority of requests have a lot in common then it is easier to create a generic solution. Otherwise it might be better to try to raise awareness of the underlying techniques.

I am increasingly using search-replace[] and my printf[] filter operators for string concatenation. 

TiddlyTweeter

unread,
May 15, 2021, 8:50:40 AMMay 15
to TiddlyWiki
@TT what form would such a macro take? Just to display combined text, or save it somewhere? And in what format/structure?

TBH I am not sure. I'm not really a programmer. The underlying issues are opaque to me. 
I can only see the surface clearly.

What I DO know is that, over time, need for basic "append" has come up often.
FWIW most were about actual combination to NEW Tiddlers. 

HOW it is done I think is quite secondary (for the end user)--just so long as it works.

If the majority of requests have a lot in common then it is easier to create a generic solution. Otherwise it might be better to try to raise awareness of the underlying techniques.

I am increasingly using search-replace[] and my printf[] filter operators for string concatenation. 

I do see you using them to good effect. Can't pretend to understand it.

Anyway
My 2 cents

Mohammad Rahmani

unread,
May 15, 2021, 10:39:12 AMMay 15
to tiddl...@googlegroups.com
WOW, great solution Saq!

If we could have some good CSS for print in TW, then we could produce wonderful output in PDF format! 



Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Mohammad Rahmani

unread,
May 15, 2021, 10:40:27 AMMay 15
to tiddl...@googlegroups.com
On Sat, May 15, 2021 at 2:24 PM Odin <odin...@gmail.com> wrote:
Thank you Saq for the solutions!! Helps a lot : )

@Mohammed, I did try a search in the TW-scripts. So I think I will add a pull request to include Saq's solutions soon!

Thank you Odin! also feel free to email me the tiddlers if you like!
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Saq Imtiaz

unread,
May 15, 2021, 12:03:32 PMMay 15
to TiddlyWiki
Just in the interest of thoroughness, option 3 from my post above can be further simplified to:

<$button> save to a single tiddler 
<$vars template="
$(accumulator)$
!! $0$

$1$
"> 
<$action-setfield $tiddler="report" text={{{ [tag[About]] :reduce[<template>printf{!!title},{!!text}] }}}/> 
</$vars> 
</$button>

However, the previous form makes it easier to understand how reduce is being used if one is not used to it.

Mohammad Rahmani

unread,
May 15, 2021, 2:08:32 PMMay 15
to tiddl...@googlegroups.com
On Sat, May 15, 2021 at 8:33 PM Saq Imtiaz <saq.i...@gmail.com> wrote:
Just in the interest of thoroughness, option 3 from my post above can be further simplified to:

<$button> save to a single tiddler 
<$vars template="
$(accumulator)$
!! $0$

$1$
"> 
<$action-setfield $tiddler="report" text={{{ [tag[About]] :reduce[<template>printf{!!title},{!!text}] }}}/> 
</$vars> 
</$button>

However, the previous form makes it easier to understand how reduce is being used if one is not used to it.

Lovely! I need to go through this! The $0$ and $1$ as place holder seems to create a lot of flexibility!

 

Saq Imtiaz

unread,
May 15, 2021, 2:44:41 PMMay 15
to TiddlyWiki
So with the printf[] operator I attached which is not a part of the TW core, $(varname)$ is replaced by a variable called varname if it exists, just like in macros.
So in the example above $(accumulator)$ is replaced with the value of the variable accumulator

$n$ is replaced by the nth operand, zero based. So $0$ is replaced by the first operand, $1$ by the second operand. 
This again takes inspiration from macros and how macro parameters are replaced, but instead of using the name of a parameter we use the position of the operand.

printf can handle an unlimited and flexible number of operands.

This might not be something everyone would find intuitive, however it has been very useful for me in my own wikis.

Mohammad Rahmani

unread,
May 15, 2021, 11:47:37 PMMay 15
to tiddl...@googlegroups.com
On Sat, May 15, 2021 at 11:14 PM Saq Imtiaz <saq.i...@gmail.com> wrote:
So with the printf[] operator I attached which is not a part of the TW core, $(varname)$ is replaced by a variable called varname if it exists, just like in macros.
So in the example above $(accumulator)$ is replaced with the value of the variable accumulator

$n$ is replaced by the nth operand, zero based. So $0$ is replaced by the first operand, $1$ by the second operand. 
This again takes inspiration from macros and how macro parameters are replaced, but instead of using the name of a parameter we use the position of the operand.

printf can handle an unlimited and flexible number of operands.

This might not be something everyone would find intuitive, however it has been very useful for me in my own wikis.

Very useful! In Python a similar method is used for printing! This is very very powerful!
I love it!
Reply all
Reply to author
Forward
0 new messages