Inconsistent referencing behaviour?

76 views
Skip to first unread message

Rick Yagodich

unread,
Oct 5, 2019, 9:10:37 AM10/5/19
to TiddlyWiki
I am attempting to create a macro that, in part, sets a system tiddler state based on behaviour.

While the basics are achievable, I need to create a different system tiddler in each instance where the macro is used. This will depend on two elements:
  • The tiddler that the macro is used in, and
  • The tiddler that the macro transcludes
Now, within the macro, I can use the following line:

 <$text text=<<currentTiddler>>/>

This will output the name of the tiddler the macro is used within.

However, I need to use currentTiddler in the name of the system tiddler path. In effect, where t is the name of the transcluded tiddler, I want to set:

<$set name="controller" value="$:/state/$currentTiddler$/section/$t$">

But, in this case, $currentTiddler$ isn't resolved. It doesn't matter if I write it as <<currentTiddler>> instead.

How am I supposed to get the name of currentTiddler to resolve into my controller path?

Sycom

unread,
Oct 5, 2019, 9:19:22 AM10/5/19
to TiddlyWiki
Maybe this

<$set name="controller" value={{{ [[$:/state/]addsuffix<currentTiddler>addsuffix[/section/]addsuffix<t>] }}}>

Regards

Sylvain
@sycom

Rick Yagodich

unread,
Oct 5, 2019, 9:36:27 AM10/5/19
to TiddlyWiki
Yes, that works. At least once I figured out how to properly reference controller within the state and set attributes.

Thank you.

(Talk about convoluted syntax!)

Mark S.

unread,
Oct 5, 2019, 12:32:53 PM10/5/19
to TiddlyWiki
Your example may have worked if you had used $(currentTiddler)$. The $(variable)$ syntax is used when you have an external variable that you want
to insert in a string.  The $argument$ syntax is used when you are passing an argument to a macro.

If all you want to do is create a unique tiddler path for each macro instance, you might consider using the qualify macro (https://tiddlywiki.com/#qualify%20Macro )

Good luck!

Rick Yagodich

unread,
Oct 5, 2019, 4:15:24 PM10/5/19
to TiddlyWiki
Thanks Mark S.

$(currentTiddler)$ simplified my macro.

It was the <<qualify>> macro's weird behaviour that caused me to hash things out this way - see the Any idea how to collapse/expand section within a tiddler thread.


Mark S.

unread,
Oct 5, 2019, 5:00:40 PM10/5/19
to TiddlyWiki
I don't think your original problem necessarily had anything to do with <<qualify>>. It was probably the "popup" option on the button.
That option meant that you could click anywhere and the state tiddler would flip.

However, there may have been a problem with the qualify and the concatenation with the heading parameter.
The line had three $ symbols and may have parsed it incorrectly. There's a new syntax for parameters

$(__parameter__)$

which I've never had a real reason to use before, but it came in handy in this case. Here's the revised version
of the original macro (which uses a heading and text, but you could modify as needed) :


\define fold(heading, text)
<$set name="controller" value=<<qualify """$:/state/section$(__heading__)$""">> >

<$reveal type="match" state=<<controller>> text="">

<$button class="tc-btn-invisible" set=<<controller>> setTo="hide">

$heading$
</$button>
$text$
</
$reveal>
<$reveal type="nomatch" state=<<controller>> text="">
<$button class="tc-btn-invisible" set=<<controller>> setTo="">

$heading$
</$button>
</
$reveal>
</$set>
\end


Rick Yagodich

unread,
Oct 5, 2019, 5:20:05 PM10/5/19
to tiddl...@googlegroups.com
Thanks Mark. You're right, it was likely the popup more than the qualify.

So, the only two difference between your and mine are:

a) I'm using a transcluded tiddler where you're passing a heading and body text, and
b) You're in some way hashing the path with <<qualify>>

Based on the description of <<qualify>>, I can't figure out if yours would allow the same heading to be folded into two tiddlers without interfering with each other.

My question then becomes: what is the value of using <<qualify>> here? What does it add? And if it's only saving the need to reference currentTiddler in the value field because it's implied in the hash, wouldn't it make more sense to have the value be $:/state/section/<<qualify "$heading$">> (or whatever the correct syntax for that is). We don't want to create loads of fully-visible qualify-named tiddlers in the edit history…

Mark S.

unread,
Oct 5, 2019, 5:31:10 PM10/5/19
to TiddlyWiki


On Saturday, October 5, 2019 at 2:20:05 PM UTC-7, Rick Yagodich wrote:
$:/state/section/<<qualify "$heading$">>

I believe that's what the supplied code is actually doing. As I understand it, the qualify macro
is most useful if you're going to be using the macro in transclusions. Especially if it's used
inside of a template tiddler. But it might work just as well with $:/state/stuff/$(currentTiddler)$
for most needs.

TonyM

unread,
Oct 5, 2019, 6:27:32 PM10/5/19
to TiddlyWiki
A quick point

Qualify responds to the current tiddler. If you change the current tiddler in a list or use the tiddler widget to set current tiddler qualify will give a different result.

Regards
Tony

Reply all
Reply to author
Forward
0 new messages