Newby and non english spoken question !!! thanks for your patience
global mymacro :
\define mymacro param1: “the current Tiddler by default”
…\end
in each thistiddler :
mymacro thistiddler works
mymacro don’t work
why ?
How write the name of current Tiddler as parameter1 by default ? I try << {{ {{< …
Must write two macros ?
define mymacro1( tiddlerparam) : I can use {{$tiddlerparam$!!fieldA}} and i can use myothermacro $tiddlerparam$
define mymacro2() : use {{!!fieldA}}
but I can’t use myothermacro
Perplixity or my web search give me wrong solution, outdated solution, too complex solutions…
Yet this is the first script we are trying to make when we enter in TiddlyWiki!
Paul, tu peux inclure des blocs de code dans tes messages en les encadrant par une ligne qui contient uniquement trois “backticks” à la suite, comme dans tiddlywiki.
This will set the currentTiddler within the macro to whatever you’ve passed in. Then, you can use just the field reference – {{!!Unicité}} – without needing to explicitly provide the tiddler title.
Alternatively, rather than using the {{!!fieldname}} transclusion “short form” syntax, you could use a full $transclude widget, like this: <$transclude $tiddler=<<__t__>> $field="Unicité"/>
or, you could use a “filtered transclusion”, like this: <$text text={{{ [<__t__>get[Unicité]] }}}/>. Note the use of the $text widget which causes the filtered transclusion result to be rendered as plain text instead of a link to the displayed field value.
Before anyone else followed up for @paulTW, I spent a long time trying to find a solution based on that kind of code, @EricShulman but the solution was not passing <<currentTiddler>> properly (was passing it as literal text)… For the “annals of failure” archive, here’s the documentation of where/why I got stuck:
(The $t$ result was good for the default (currentTiddler) but would break tiddler names with spaces — it failed exactly where <<__t__>> succeeded. UPDATE: … And using "$t$" works and fails exactly parallel to <<__t__>>)
The parameters widget was going to be my next approach… Luckily, the reply with solutions by @tw-FRed showed up after some time, and put me out of my misery!
EDIT: Nudging for a general discussion of this problem in new thread [EDIT #2 — I removed that thread before it got any replies, not confident that this is a constructive discussion at this moment]
Ugh, that’s among the variants I thought I had tried! …
UPDATE: Well… yeah that fixes the multi-word titles BUT BREAKS the currentTiddler (passes <<currentTiddler>> as dumb text to the tiddler widget). That’s the headache…
No. I think it’s an inherent part of WT structure. You can’t define dynamic defaults for a macro. What I’ve done in the past is to have one macro call a second, helper macro. See code below.
Of course, “\define” is now deprecated, so procedures with the parameter widget are the way forward. Not entirely intuitive, but at least documented.
Yes, I was suspecting that things like this were the reason for deprecation, and introduction of parameter widget.
It’s frustrating for novices that it seems to work — until it doesn’t… and specifying the default parameter inline is just so much more intuitive and readable.