How to pass a variable to a macro

94 views
Skip to first unread message

vpl

unread,
Mar 4, 2020, 3:35:42 PM3/4/20
to TiddlyWiki
Hi,

I've developped a small macro but can't figure out how to pass it a variable which is a field of another tiddler

The following call works fine. I pass the value '20200304175209359' to the macro which use it
<$list filter=<<select_tiddlers timeStamp:'20200304175209359'>>>
<$link /><br>

But When I try to pass the value of the field timestamp from tiddler ref-timeStamp, what is passed is the string {ref-timeStamp!!timestamp}

<$list filter=<<select_tiddlers timeStamp:[[{ref-timeStamp!!timestamp}]]>>>
<$link /><br>
</$list>

Any idea and help ...

THanks a lot

Regards

Mat

unread,
Mar 4, 2020, 3:49:34 PM3/4/20
to TiddlyWiki
I'm interpreting "select_tiddlers" to be the "small macro" you wish to pass the timestamp to.

Further, I'm guessing this macro returns some set of strings (titles or otherwise) that you then wish to use as argument for the list filter attribute.

You can do it like so:

\define select_tiddlers()
whatever your macro does
and you call the timestamp using <<timestamp>>
\end

<$set name=timestamp value={{ref-timeStamp!!timestamp}}>
<$set name=sel_tid value=<<select_tiddlers>> >
<$list filter=<<sel_tid>> >

</$list>
</
$set>
</$set>

I think this should work. You might have to do this instead

<$list filter="[enlist<sel_tid>]" >

etc.

<:-)

TonyM

unread,
Mar 4, 2020, 5:22:33 PM3/4/20
to TiddlyWiki
Vpl

Even when we create our own macros using the \define you can use the macrocall widget instead of
<<select_tiddlers timeStamp:'20200304175209359'>>

<$macrocall $name="select_tiddlers" timeStamp='20200304175209359'/>
<$macrocall $name="select_tiddlers" timeStamp={{tiddlername!!fieldname}}/>
<$macrocall $name="select_tiddlers" timeStamp={{tiddlername}}/>
<$macrocall $name="select_tiddlers" timeStamp={{!!fieldname}}/>
<$macrocall $name="select_tiddlers" timeStamp=<
<variableormacro>> />

Regards
Tony

TonyM

unread,
Mar 4, 2020, 6:21:38 PM3/4/20
to TiddlyWiki
Post script

If you want to construct your parameter the triple braces method is also useful

<$macrocall $name="select_tiddlers" timeStamp={{{ filter }}}/>

<$macrocall $name="select_tiddlers" timeStamp={{{ [
<variablename>] }}}/> etc..

But macros themself can access data in the tiddler calling it, or global macros

eg using $(variablename)$ in the macro.


Tony

TonyM

unread,
Mar 4, 2020, 6:44:37 PM3/4/20
to TiddlyWiki
Post Post script

Below not tested, but believed correct

Using variables in the called macro
\define macroname() $(var1)$ $(var2)$ {{textreference}}

<$set name=var1 value={{textref}} emptyValue="default">
<$set name=var2 filter="[all[current]get[fieldname]]" emptyValue="default">
<<macroname>>
</$set></$set>


Also From TiddlyWiki
A similar effect to a parameterised macro call can be produced by setting variables around a transclusion.

Calling tiddler
<$set name=var1 value={{textref}} emptyValue="default">
<$set name=var2 filter="[all[current]get[fieldname]]" emptyValue="default">
{{||templatetiddler}}
<!-- note {|| which operated on the calling tiddler as currentTiddler -->
</$set></$set>


templatetiddler
<<var1>>
$(var1)$
<!-- not sure-->
{{!!fieldname}} and other text references from calling tiddler

Note: A design pattern I use is to always make a macro operate on the currentTiddler, you can always use the tiddler widgety or a list to alter the currentTiddler variable to have a macro operate on a listed or other tiddler.


If anyone can think of another method do share

Regards
Tony

Mohammad

unread,
Mar 5, 2020, 1:52:00 AM3/5/20
to TiddlyWiki


On Thursday, March 5, 2020 at 3:14:37 AM UTC+3:30, TonyM wrote:
Post Post script

Below not tested, but believed correct

Using variables in the called macro
\define macroname() $(var1)$ $(var2)$ {{textreference}}

<$set name=var1 value={{textref}} emptyValue="default">
<$set name=var2 filter="[all[current]get[fieldname]]" emptyValue="default">
<<macroname>>
</$set></$set>


Also From TiddlyWiki
A similar effect to a parameterised macro call can be produced by setting variables around a transclusion.

Calling tiddler
<$set name=var1 value={{textref}} emptyValue="default">
<$set name=var2 filter="[all[current]get[fieldname]]" emptyValue="default">
{{||templatetiddler}}
<!-- note {|| which operated on the calling tiddler as currentTiddler -->
</$set></$set>


templatetiddler
<<var1>>
$(var1)$
<!-- not sure-->
{{!!fieldname}} and other text references from calling tiddler


The $(var1)$ does not work except you put it inside a tiddler!
Eric Shulman has some good stuffs on these if you search TW-Scripts or this forum.

vpl

unread,
Mar 5, 2020, 2:44:08 AM3/5/20
to TiddlyWiki
Thanks guys for all of these directions of work.
Need to explore and educate a bit myself on these different options

Have a nice day

Regards
Reply all
Reply to author
Forward
0 new messages