[TW5] Toggle macro

286 views
Skip to first unread message

Andrew

unread,
Oct 19, 2015, 2:51:22 AM10/19/15
to TiddlyWiki
Hello again. I'm trying to construct a macro that toggles between tiddlers like a chain of buttons. I set it up to save state in a temp file because I wanted to be able to clone the tiddler that the button is in and have them work independently. I can't seem to figure out how to set the field in the temp tiddler to the value in the target field of my second button. Here is what I have so far. So, the button is supposed to set the state field with the name of the tiddler title that I am trying to pass to the macro bit it ends up setting it to text "<$view tiddler=<<t>> field="target" />" instead of "TagPill1c". Any suggestions welcome?

Jed Carty

unread,
Oct 19, 2015, 4:09:33 AM10/19/15
to TiddlyWiki
There are a few ways to do this, perhaps the simplest is to use the tiddler widget. If you change the second set widget from <$set name="t" value={{$:/temp/$(currentTiddler)$!!$label$}}> to <$tiddler tiddler={{$:/temp/$(currentTiddler)$!!$label$}}> and then make the second button

<$button set=<<s>> setTo={{!!target}} class="tc-btn-invisible">
<<t2>>
</$button>

The tiddler widget changes the value of currentTiddler inside the widget to whatever tiddler you set, it can let you avoid a lot of problems in situations like this.

Another way is to use a variable and macro like is done here.

Tobias Beer

unread,
Oct 19, 2015, 8:05:26 AM10/19/15
to TiddlyWiki
Hi Andrew,

Do you mean something like...:

cycletags @ tb5

...but with all buttons visible / clickable at any time?


how to set the field in the temp tiddler to the value in the target field of my second button.

That's why the above is a js macro. But why do you precisely need to show / act on the next one?
Can you give a specific example for how that is to work / explain the goals and whys?

Best wishes,

— tb

Matabele

unread,
Oct 19, 2015, 11:05:11 AM10/19/15
to tiddl...@googlegroups.com
Hi

If it's a kind of slideshow you're after, you can walk along a chain of titles in a list. Put this code in each tiddler in the chain:

<$set name="before" filter="[list[lists!!list]before{!!title}]">
<$set name="after" filter="[list[lists!!list]after{!!title}]">
<$button set="lists!!target" setTo=<
<before>>>Before</$button>
<$button set="lists!!target" setTo=<
<after>>>After</$button>
</$set></$set>

<$view tiddler="lists" field="target"/>


-- write a list of the titles of each tiddler in a list somewhere -- 'lists!!list' for this example
-- for this example I have used the field lists!!target as the 'state' field
-- the <$view> widget is to display whats going on
-- open a few of the tiddlers and click some buttons to see how this works

regards

Matabele

unread,
Oct 19, 2015, 12:58:19 PM10/19/15
to tiddl...@googlegroups.com
Hi

If you want the list to roll around at the ends -- use this code instead (need this only in the first and last tiddlers in the chain, but can use this same code in all of the tiddlers):

<$set name="before" filter="[list[lists!!list]last[]][list[lists!!list]before{!!title}]+[last[]]">
<$set name="after" filter="[list[lists!!list]after{!!title}][list[lists!!list]first[]]+[first[]]">
<$button set="lists!!target" setTo=<
<before>>>Before</$button>
<$button set="lists!!target" setTo=<
<after>>>After</$button>
</$set></$set>

<$view tiddler="lists" field="target"/>

regards

Matabele

unread,
Oct 19, 2015, 1:24:29 PM10/19/15
to tiddl...@googlegroups.com
Hi

With single tiddler navigation thrown in (and the superfluous $view widget removed) -- the code will look like this:

<$set name="before" filter="[list[lists!!list]last[]][list[lists!!list]before{!!title}]+[last[]]">
<$set name="after" filter="[list[lists!!list]after{!!title}][list[lists!!list]first[]]+[first[]]">
<$button set="$:/StoryList!!list" setTo=<<before>>>Before</$button>
<$button set="$:/StoryList!!list" setTo=<
<after>>>After</$button>
</$set></$set>

Slideshows are a common usage -- I have, therefore, posted a working sample here for reference.

regards

Jed Carty

unread,
Oct 19, 2015, 2:04:40 PM10/19/15
to TiddlyWiki
I didn't actually think to put up examples of other slideshows, but there are a few different examples.
This one Birthe made stands out, and Jeremy made this, the source is here. There is a simpler implementation I made here, but I think it is pretty much just the same thing as Matabeles example put into an application.
There are probably more, but I think the others are all small variations on the same thing.

Andrew

unread,
Oct 20, 2015, 1:47:26 AM10/20/15
to TiddlyWiki
Thank you all very much for your suggestions. While they didn't solve my problem directly, they have given me something to work with. I've continued hacking and have something that seems to work now. I still don't know if I am doing something wrong even though it seems to work.
Check out my new updated Toggle Macro. And here is an example of it working. Any feedback welcome. If it needs to be rewritten in a different way or more elegant way or functionally different, please let me know. I feel like I am reinventing something that probably has already been done a different way.

Matabele

unread,
Oct 20, 2015, 7:07:04 AM10/20/15
to TiddlyWiki
Hi

OK -- sorry, I misunderstood your usage. 

There is no restriction with the $reveal widget to use only a pair of widgets, one with 'match' and one with 'nomatch'. You may use as many $reveal widgets as necessary (in different places) each of which is set to 'match' and reveals itself iff there is a match to the state tiddler value.

This permits:
-- buttons that cycle through many values (each $reveal widget revealing a button that sets the state to match the next widget in the chain)
-- buttons that reveal several different sections of Wikitext in any location

This second facility may simplify your code, as both the tag itself, and some text elsewhere can be revealed/hidden with the same button (both $reveal widgets are set to reveal if there is a match to the same value of the state tiddler.)
<$reveal type="match" state="$:/state/Reveal" text="hide">

<$button set="$:/state/Reveal" setTo="show">Next</$button>

</$reveal>
<$reveal type="match" state="$:/state/Reveal" text="show">

<$button set="$:/state/Reveal" setTo="showmeto">Next</$button>

! This is the revealed content
And this is some text

</$reveal>
<$reveal type="match" state="$:/state/Reveal" text="showmeto">

<$button set="$:/state/Reveal" setTo="hide">Next</$button>

! This is the revealed content
And this is some text

</$reveal>

<$reveal type="match" state="$:/state/Reveal" text="showmeto">

! and this is some more revealed content somewhere else
And this is some text

</$reveal>


Note: The state tiddler needs to be 'booted' with one of the appropriate values for one of the buttons in the chain to show

regards

Andrew

unread,
Oct 20, 2015, 9:03:15 AM10/20/15
to TiddlyWiki
Hi Matabele, It now actually can daisy chain any number of buttons or tiddlers and display anything from the toggle tiddler's text field. The break through that I had was figuring out how triple quotes are used in conjuction with the set field to make the fields of my temp tiddler to be able to be used. I wish I knew all the terminology.
My next step is to add features like tooltip and anything else anyone suggests. Any suggestions?

Matabele

unread,
Oct 20, 2015, 9:38:28 AM10/20/15
to TiddlyWiki
Hi

The triple quoted attribute values are very useful -- you can include wikitext formatting, indirect references and even macro code within the triple quoted block. Tooltips are straightforward, simply add: tooltip="My Tooltip" -- I guess for your usage case this might be an indirect reference, macro or variable: tooltip={{!!mytooltip}} or tooltip=<<mytooltip>>

regards

Andrew

unread,
Oct 21, 2015, 12:46:24 AM10/21/15
to TiddlyWiki
Is there any way to rewrite the following any more elegantly?
\define d()
$:/temp/$(currentTiddler)$!!$(a)$
\end

\define toggle-body(a,b,c)
<$set name="a" value="""$a$""">
<$set name="b" value="""$b$""">
<$set name="c" value="""$c$""">
<$reveal type="match" state=<<d>> text="">
<$button set=<<d>> setTo=<<b>> class="tc-btn-invisible">
<$transclude tiddler=<<a>> />
</$button>
</$reveal>
<$reveal type="nomatch" state=<<d>> text="">
<$button set=<<d>> setTo={{$c$!!target}} class="tc-btn-invisible">
<$transclude tiddler=<<c>> />
</$button>
</$reveal>
</$set>
</$set>
</$set>
\end

\define toggle(a)
<$macrocall $name="toggle-body" a=$a$ b={{$a$!!target}} c={{$:/temp/$(currentTiddler)$!!$a$}}/>
\end

Matabele

unread,
Oct 21, 2015, 1:00:09 AM10/21/15
to TiddlyWiki
Hi

For starters, you could replace the 3 $set widgets with a $vars widget:

\define d()
$
:/temp/$(currentTiddler)$!!$(a)$
\end

\define toggle-body(a,b,c)
<$vars a="""$a$""" b="""$b$""" c="""$c$""">

<$reveal type="match" state=<<d>> text="">
<$button set=<<d>> setTo=<<b>> class="tc-btn-invisible">
<$transclude tiddler=<<a>> />
</
$button>
</$reveal>
<$reveal type="nomatch" state=<<d>> text="">
<$button set=<<d>> setTo={{$c$!!target}} class="tc-btn-invisible">
<$transclude tiddler=<<c>> /
>
</$button>
</
$reveal>
</$vars>

\end

\define toggle(a)
<$macrocall $name="toggle-body" a=$a$ b={{$a$!!target}} c={{$:/
temp/$(currentTiddler)$!!$a$}}/>
\end

regards

Matabele

unread,
Oct 21, 2015, 1:07:05 AM10/21/15
to TiddlyWiki
Hi

Give this a try (without being able to test the code I don't know if this will work):

\define d()
$
:/temp/$(currentTiddler)$!!$(a)$
\end

\define toggle(button)
<$vars a="""$button$""" b="""{{$button$!!target}}""" c="""{{$:/temp/$(currentTiddler)$!!$button$}}""">

<$reveal type="match" state=<<d>> text="">
<$button set=<<d>> setTo=<<b>> class="tc-btn-invisible">
<$transclude tiddler=<<a>> />
</
$button>
</$reveal>
<$reveal type="nomatch" state=<<d>> text="">
<$button set=<<d>> setTo={{$c$!!target}} class="tc-btn-invisible">
<$transclude tiddler=<<c>> /
>
</$button>
</
$reveal>
</$vars>
\end

regards

On Wednesday, 21 October 2015 06:46:24 UTC+2, Andrew wrote:

Andrew

unread,
Oct 21, 2015, 1:20:17 AM10/21/15
to TiddlyWiki
That didn't completely work, I had to revert to the following and I still don't know what I'm doing:

\define d()
$:/temp/$(currentTiddler)$!!$(a)$
\end

\define toggle-body(a,b,c)
<$vars a="""$a$""" b="""$b$""" c="""$c$""">
<$reveal type="match" state=<<d>> text="">
<$button set=<<d>> setTo=<<b>> class="tc-btn-invisible">
<$transclude tiddler=<<a>> />
</$button>
</$reveal>
<$reveal type="nomatch" state=<<d>> text="">
<$button set=<<d>> setTo={{$c$!!target}} class="tc-btn-invisible">
<$transclude tiddler=<<c>> />
</$button>
</$reveal>
</$vars>
\end

\define toggle(a)
<$macrocall $name="toggle-body" a=$a$ b={{$a$!!target}} c={{$:/temp/$(currentTiddler)$!!$a$}}/>
\end

Any more suggestions?

Matabele

unread,
Oct 21, 2015, 10:34:11 AM10/21/15
to TiddlyWiki
Hi

Looks like the code does something like this:

\define toggle(button, altbutton)
<$reveal type="match" state="$:/temp!!$button$" text="show">
<$button set="$:/temp!!$button$" setTo="hide" class="tc-btn-invisible">
<$transclude tiddler="$button$"/>
</$button>
</
$reveal>
<$reveal type="match" state="$:/temp!!$button$" text="hide">
<$button set="$:/temp!!$button$" setTo="show" class="tc-btn-invisible">
<$transclude tiddler="$altbutton$" />
</$button>
</
$reveal>
\end

<<toggle "Content" "OtherContent">>

To get this to work -- bootstrap the '$:/temp' tiddler with a field 'Content' with a value of "hide"

Create the two content tiddlers with some text

regards

Andrew

unread,
Oct 22, 2015, 9:13:12 AM10/22/15
to TiddlyWiki
@Matabele, thank you again for your feedback. My macro is actually more complex than just 2 items. It is called using the initial tiddler but then can daisy chain through unlimited additional tiddlers. I was just looking to see if there was a better way of defining the variables than declaring them on one macro and passing them to a second macro. I found a previous explaination from Jeremy with the following but couldn't figure out how to use it: Problem with macros and default values. https://www.google.com/url?sa=t&source=web&rct=j&url=https://groups.google.com/forum/m/%23!msg/tiddlywiki/6NYTz7WyuuY/ENu7cAu8nlkJ&ved=0CCgQFjAEahUKEwjulamYk9bIAhWLsIAKHZkQAnA&usg=AFQjCNF4ZuCA79SeCltd8kBIzArzeBbKsQ&sig2=DYZAF6hCumEE3zfy3EHZtg

Tobias Beer

unread,
Oct 22, 2015, 12:39:41 PM10/22/15
to TiddlyWiki
Hi Andrew,

Can you please expand a little more on the idea behind this than any implementation.
I see that you do some toggling but then for what purpose, how do you intend to use it?
...and most importantly, how does that differ from what cycletags does?

Best wishes,

— tb

Andrew

unread,
Oct 22, 2015, 3:47:54 PM10/22/15
to TiddlyWiki
You are very wise Tobias. I don't yet have any hooks into what it can do yet. It's more like I'm building an engine out of parts from the core rather than using js that isn't part of the core. If I can push the features to the fields of the tiddler buttons, it will make it more functional and dynamic. With native parts comes speed as long as done right. It helped me understand macro variables better and now I am evaluating how to write a <<default>> macro using the existing core parts without using js. I've seen it before where double bars were used but haven't figured that out yet. I think once I do, it may change my Toggle macro. I hope I haven't confused you.

Tobias Beer

unread,
Oct 22, 2015, 5:51:58 PM10/22/15
to TiddlyWiki
Hi Andrew,

Nay worries, no confusion here, just curiosity...
trying to understand the what it is that you're after rather than the how.
Always comes first, possibly preceded by a why...
but maybe that all too often comes last. ;-)

It's good to try and use all the bells and whistles
that are already there to create a tune,
rather than add "new" sounds to the soundspectrum.

Best wishes,

— tb

Andrew

unread,
Oct 22, 2015, 8:17:50 PM10/22/15
to TiddlyWiki
The What: Dynamic console buttons for the system aboard a starship (future wishful thinking.) I mean really what is Tiddlywiki anyway. With touch screens and some tech and some time, woot, woot. In the Star Trek fictional universe, LCARS (/ˈɛlkɑrz/; an acronym for Library Computer Access/Retrieval System) is a computer operating system. Sounds like Tiddlywiki 5.
The Why: I feel it should be TCARS (Tiddlywiki Computer Access/Retieval System).
The How: Widgets, Macros, Tiddlers, Fields, Tags, SVG, and whatever other glorious magical thing that Jeremy invents.

Andrew

unread,
Oct 22, 2015, 8:36:34 PM10/22/15
to TiddlyWiki
Hi Tobias,
I was wondering if you might know how to use the double bars || to declare in a macro something like:
Use the title of the initial tiddler passed as a parameter with the first macro call if the field in the status field is null or empty.
In my macro, I want to set the value of $c$ to the value of $a$ if $s$ is null or empty.

Matabele

unread,
Oct 23, 2015, 12:33:20 AM10/23/15
to TiddlyWiki
Hi

Have a look at 'conditional variable assignment' with the $set widget: http://tiddlywiki.com/#:SetWidget

 -- this can be used to set the value of a variable, depending upon the output of a filter expression

regards

Tobias Beer

unread,
Oct 23, 2015, 5:32:08 AM10/23/15
to tiddl...@googlegroups.com
Hi Andrew,

I was wondering if you might know how to use the double bars || to declare in a macro something like... 

If you mean the {{||some-template}} syntax you can sure use that in a macro, e.g.

\define some-macro(x,y)
<$list filter="[all[current]has[$x$]]">
{{$x$||some-template}}
</$list>
<$list filter="[all[current]!has[$x$]]">
{{$y$||some-template}}
</$list>
\end

The thing with this is:

I want to set the value of $c$ to the value of $a$ if $s$ is null or empty.

...so long as I have trouble understanding what you're eventually trying to achieve,
it is difficult to evaluate whether using a dynamically defined variable "$c$" makes sense and how.
You see, I would probably also not use "$s$" as a parameter if it was a field.
So, it's mildly difficult to anticipate how and why you mean "set $c$".
Where is $c$ and its value to take effect?

For example...

\define some-macro(some-tiddler,some-field,some-variable,some-value)
<$list filter="[<$some-tiddler$>has[$some-field$]">
<$set name="""$some-variable$""" value="$some-value$""">
what you actually want to do needs to be here, inside the $set, e.g.
{{||some-template}}
</$set>
</$list>
\end

...what in all of the above actually needs to be a paramater and what doesn't or why, I could not tell right now.

I would encourage you to follow slightly more specific goals that achieve something tangible that you're after. Exploring all that is possible sure can be a fruitful exercise. However, on an as abstract level as this, it is hard to imagine anything, to decipher what you're going for, because the why and what is a wee blurry... unless you're that kind of artist that just swings that brush to eventually see later what came out of it all. :D

Best wishes,

— tb
Reply all
Reply to author
Forward
0 new messages