Help with the helpbutton macro..

60 views
Skip to first unread message

Ste

unread,
Feb 23, 2021, 11:39:31 AM2/23/21
to TiddlyWiki
Hello Good people,
Many moons ago I picked up the Helpbutton macro from....Jed?...Mark?  (sorry)

\define HelpButton(label, ButtonText:?)
^^(<$button popup="""$:/temp/popup/$(currentTiddler)$/$label$""" class='tc-btn-invisible tc-tiddlylink'>$ButtonText$</$button>)<$reveal type='popup' state="""$:/temp/popup/$(currentTiddler)$/$label$"""><div class='tc-drop-down' style='width:1500px;max-width:75vw;white-space:pre-wrap;padding:10px;text-align:left;font-size:1.5em;border-radus:0.5em;'><$transclude field="""$label$"""/></div></$reveal>^^
\end

Usage:

<<HelpButton fieldname>>

<<HelpButton fieldname 'why?'>>

Now, I have a tabs list:
<<tabs tabsList:"[[tiddler1]] [[tiddlertwo]] " class:"tc-vertical">>

But the help button shows when in the tabbed list butasefaf.PNG
but works perfectly in the original tiddler.

Any insights?

Thank you.

Ste

Eric Shulman

unread,
Feb 23, 2021, 2:23:23 PM2/23/21
to TiddlyWiki
On Tuesday, February 23, 2021 at 3:39:31 AM UTC-8 Ste wrote:
\define HelpButton(label, ButtonText:?)
^^(<$button popup="""$:/temp/popup/$(currentTiddler)$/$label$""" class='tc-btn-invisible tc-tiddlylink'>$ButtonText$</$button>)<$reveal type='popup' state="""$:/temp/popup/$(currentTiddler)$/$label$"""><div class='tc-drop-down' style='width:1500px;max-width:75vw;white-space:pre-wrap;padding:10px;text-align:left;font-size:1.5em;border-radus:0.5em;'><$transclude field="""$label$"""/></div></$reveal>^^
\end
Now, I have a tabs list:
<<tabs tabsList:"[[tiddler1]] [[tiddlertwo]] " class:"tc-vertical">>
...the help button shows when in the tabbed list but works perfectly in the original tiddler.

The problem arises because popup's "state" tiddler ($:/temp/popup/$(currentTiddler)$/$label$) depends on the value of $(currentTiddler)$.

In the "original" tiddler, this value is the title of that tiddler.  However, when shown in a tab, the value is the title of the tiddler containing the entire tab set, rather than the title of the tab content tiddler itself.

The currentTiddler variable is not affected by the tabs macro. This can put you in trouble if the list of tabs includes tiddlers that depend on the value of the currentTiddler,

One way to account for this is to wrap your macro within a $tiddler widget, like this:
<$tiddler tiddler=<<currentTab>><<HelpButton ...>></$tiddler>

What this does:
* when the content is shown in the "original" tiddler, the value of <<currentTab>> is undefined, so the $tiddler widget has no effect
* when the content is shown in a tab, the value of <<currentTiddler>> is set to the same as the <<currentTab>>

Note that, to make this usage a bit cleaner, you could re-write your code as follows:
\define HelpButton(label, ButtonText:?) <$tiddler tiddler=<<currentTab>><<HelpButton_inner $label$ $ButtonText$>></$tiddler>
\define HelpButton_inner(label, ButtonText:?)
^^(<$button popup="""$:/temp/popup/$(currentTiddler)$/$label$""" class='tc-btn-invisible tc-tiddlylink'>$ButtonText$</$button>)<$reveal type='popup' state="""$:/temp/popup/$(currentTiddler)$/$label$"""><div class='tc-drop-down' style='width:1500px;max-width:75vw;white-space:pre-wrap;padding:10px;text-align:left;font-size:1.5em;border-radus:0.5em;'><$transclude field="""$label$"""/></div></$reveal>^^
\end

The first macro adds the $tiddler wrapper and then invokes the actual HelpButton code (now renamed HelpButton_inner)

enjoy,
-e

Ste

unread,
Feb 23, 2021, 4:37:34 PM2/23/21
to TiddlyWiki
Thank you Eric,
Much appreciated.  I had thought it might be the words 'current tiddler'  but had no clue what to do about it!

Ste

unread,
Feb 23, 2021, 5:54:01 PM2/23/21
to TiddlyWiki
Just a minor thing for anyone else, Eric's awsome solution is missing a > after <$tiddler tiddler=<<currentTab>> so it should be <$tiddler tiddler=<<currentTab>>> and works like a charm!  Thanks once again.
Reply all
Reply to author
Forward
0 new messages