Save the output of a list-widget to the text of another tiddler?

146 views
Skip to first unread message

si

unread,
Apr 22, 2021, 5:44:49 PM4/22/21
to TiddlyWiki
I'm trying to create a button that will take the output generated by the following list-widget and set it as the text of another tiddler. The text needs to retain all its original formatting.

Here is the widget whose output I want to save (note that the operator used is from the new Streams pre-release, but I don't think that this is relevant to my question):

<$list filter="[<currentTiddler>get-stream-nodes[]]">
<$transclude mode=block/>
</$list>

I guess I want to get the output of this widget into a variable, and then use the button-widget with "setField" to save it into another tiddler.

I have tried using something like <$set name=myText filter="[<currentTiddler>get-stream-nodes[]get[text]]"> but I end up losing all the formatting.

Anyone able to help me out here?

Thanks in advance.

Charlie Veniot

unread,
Apr 22, 2021, 9:57:54 PM4/22/21
to TiddlyWiki
G'day si,

Not sure if the code below will work for you.

I created a tiddler with that code, and simulated with a "hard-coded" filter to grab tiddlers "a" and "b".

The process sets the text for the aggregator tiddler to whatever it had plus the text from tiddlers a and b.

That was fun !


\define my-actions()

<$list filter="[[a]] [[b]]">
<$action-setfield $tiddler="aggregator" $field="text" $value={{{ [[aggregator]get[text]] [<currentTiddler>get[text]] +[join[<br>]]  }}}/>
</$list>

\end


<$button actions=<<my-actions>>>
Click me!
</$button>

Saq Imtiaz

unread,
Apr 23, 2021, 2:43:45 AM4/23/21
to TiddlyWiki
@si

Firstly note that the new filters introduced with Streams are still subject to change.

Secondly, the get-stream-nodes[] filter currently as includes the tiddler used as input in the titles it returns. 
So you may wish to trigger the code to consolidate the nodes from another tiddler, or change the filter expression to get all the nodes to [<currentTiddler>get-stream-nodes[]] -[<currentTiddler>]

Assuming you want to combine the raw wikitext of all of the nodes, you can do this:

<$button> save nodes to a single tiddler
<$vars lb="

">
<$vars text={{{ [<currentTiddler>get-stream-nodes[]] -[<currentTiddler>] :reduce[get[text]addprefix<lb>addprefix<accumulator>] }}}>
<$action-setfield $tiddler="report" text=<<text>>/>
</$vars>
</$vars>
</$button>

If you want the output to be HTML, then you need to use the wikify widget.
Hope this helps,

Saq

si

unread,
Apr 23, 2021, 7:29:42 AM4/23/21
to TiddlyWiki
Thanks a lot to you both!

>>> Firstly note that the new filters introduced with Streams are still subject to change.

Yep I'm just experimenting, I'll wait until the official release before using Streams for any actual work.

>>> Secondly, the get-stream-nodes[] filter currently as includes the tiddler used as input in the titles it returns. 
So you may wish to trigger the code to consolidate the nodes from another tiddler, or change the filter expression to get all the nodes to [<currentTiddler>get-stream-nodes[]] -[<currentTiddler>]

I'm actually trying to create a button to move an entire Stream into the parent tiddler as normal text, so I do want to include the text of the input tiddler in my output.

This is what I ended up with in case anyone is interested:

<$button>
<$action-confirm $message="Do you wish to move this stream to a single tiddler?">
<$vars lb="

">
<$vars text={{{ [<currentTiddler>get-stream-nodes[]] :reduce[get[text]addprefix<lb>addprefix<accumulator>] }}}>
<$action-setfield $tiddler=<<currentTiddler>> text=<<text>>/>
<$action-deletetiddler $filter="[<currentTiddler>get-stream-nodes[]] -[<currentTiddler>]"/>
<$action-deletefield stream-list stream-type/>
</$vars>
</$vars>
</$action-confirm>
Sqeeze this Stream into a single tiddler
</$button>


Seems to do the job, please let me know if I'm doing anything risky here!

Thanks again for your help.

Ray Vermey

unread,
Apr 23, 2021, 8:06:06 AM4/23/21
to Mohammad Rahmani
Aha!
Now i can change fields!
That is great!
However, can i accomplish this also without having to press a button?
Like that is is activated when saving the tiddler??

Ray

Op vr 23 apr. 2021 om 03:58 schreef Charlie Veniot <cj.v...@gmail.com>:
--
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/11889b30-cbf8-4a7a-813d-4d3c7e4da320n%40googlegroups.com.

Saq Imtiaz

unread,
Apr 23, 2021, 9:13:31 AM4/23/21
to TiddlyWiki
@si looks good, well done on using <$action-confirm>, that put on a smile on my face.

Perhaps move the action widgets to the action attribute of the button widget, inline surrounded by triple quotes or as a macro. In general, action widgets inside the body of a button can be buggy and should not be relied upon.

Reply all
Reply to author
Forward
0 new messages