[TW 5.1.23] New features - Toggle operator and Datat tiddler

226 views
Skip to first unread message

Mohammad Rahmani

unread,
Jan 1, 2021, 9:46:14 AM1/1/21
to tiddl...@googlegroups.com
I use data tiddler (Json tiddler) to store settings and configs of a plugin or other tools.

Below is an example how to toggle/switch a value in a data tiddler (e.g. myTest)
It uses a pair of  key: mode and valueauthor-mode / presentation-mode

Go to https://tiddlywiki.com/ and create a tiddler and give a try!


<$vars tid="myTest">

<$button>Toggle
<$list filter="[<tid>getindex[mode]!match[author-mode]!match[presentation-mode]]">
<$action-setfield $tiddler=<<tid>> $index="mode" $value=""/>
</$list>

<$action-listops $tiddler=<<tid>> $index="mode" $subfilter="+[toggle[author-mode],[presentation-mode]]" />
</$button>

;Result
:<$text text={{{[<tid>getindex[mode]]}}}/>
</$vars>




Best wishes
Mohammad

Mark S.

unread,
Jan 1, 2021, 4:07:23 PM1/1/21
to TiddlyWiki
Hi Mohammad!

Interesting! But the first list loop doesn't seem to be necessary.

Mohammad Rahmani

unread,
Jan 2, 2021, 12:37:10 AM1/2/21
to tiddl...@googlegroups.com
Hi Mark,

 Yes, the first loop is not necessary in all cases except one, if a user or another action sets a third value in that index of data tiddler.
 As toggle is a listops operator, it does not toggle the whole value, so you may see your code has appended a value to the list of
 current values.
 This issue happened when I tried to use the code for a page control button to switch the day/light palette.

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/15017eed-b72e-4848-bf2c-f7223fcd062fn%40googlegroups.com.

Mark S.

unread,
Jan 3, 2021, 3:13:26 PM1/3/21
to TiddlyWiki
Ok, I think you can do it without the list widget using this instead of the action-listops:

<$action-setfield $tiddler=<<tid>> $index="mode" $value={{{ [<tid>getindex[mode]compare:string:eq[author-mode]][<tid>getindex[mode]compare:string:eq[presentation-mode]]+[toggle[author-mode],[presentation-mode]] }}} />

The thing thing is, I don't quite understand how toggle works, and I feel either toggle is buggy or the documentation is. If you don't use it with the +[xxx] construction, it will use the entire pool of tiddlers to output at least one tiddler name. But it will put out exactly one tiddler name. And what is the difference inside of a filter between a "list" and a "title list" ?

At a very minimum, this line is grammatically incorrect: " If neither is present, the first parameter takes precedence is added to the list."

(Probably wants an "and" before "is" )

Mohammad Rahmani

unread,
Jan 4, 2021, 12:32:34 AM1/4/21
to tiddl...@googlegroups.com
Hi Mark,
 Nice solution! Saq is the developer behind toggle and cycle operators. As much as I know toggle is a listop operator and that is the reason for such behaviour.
Of course Saq can explain this much better than me.

Best wishes
Mohammad


TiddlyTweeter

unread,
Jan 4, 2021, 2:58:43 AM1/4/21
to TiddlyWiki
Toggles/Cyclers are very, very useful!

But I think I need to see more examples to actually understand how to implement them in TW.

One common use case, for theoretical example, could be cycling through Stylesheets. The point being to have one button that toggles through a set of different ways a TW could look. That would be neat & user supportive!

Just thoughts
TT

Mohammad Rahmani

unread,
Jan 4, 2021, 11:13:58 PM1/4/21
to tiddl...@googlegroups.com
Hi Josiah,


On Mon, Jan 4, 2021 at 11:28 AM TiddlyTweeter <Tiddly...@assays.tv> wrote:
Toggles/Cyclers are very, very useful!

But I think I need to see more examples to actually understand how to implement them in TW.

One common use case, for theoretical example, could be cycling through Stylesheets. The point being to have one button that toggles through a set of different ways a TW could look. That would be neat & user supportive!

Have a look here:


It shows how to cycle in color palettes.

--Mohammad

TiddlyTweeter

unread,
Jan 6, 2021, 1:29:31 AM1/6/21
to TiddlyWiki
M,

Very good example! Thanks.

TT

Reply all
Reply to author
Forward
0 new messages