Confusion on variables and parameters

60 views
Skip to first unread message

Jon Dyer

unread,
Nov 2, 2020, 12:53:13 PM11/2/20
to tiddl...@googlegroups.com
I think I'm not understanding something essential about access to variables vs. params in macros and Wikitext. Suppose in a macro I'm writing I want one variable to default to the value of another if it isn't present. I've tried to use the SetWidget to make this work, but no matter what I try I can't seem to overwrite the parameter value with what I have in the <$set...> part. Can you tell what I'm doing wrong?

For a concrete example:


\define mymac(title,label)

<$text text="""Title: $title$"""/>
<br>
<$text text="""Label: $label$"""/>
<br>

<$set name="label" filter="$label$" value="$label$" emptyValue="""$title$""">
<$text text="""Title: $title$"""/>
<br>
<$text text="""Label: $label$"""/>
</$set>

\end


<<mymac title:"test" label:"hello">>


Mark S.

unread,
Nov 2, 2020, 1:57:27 PM11/2/20
to TiddlyWiki
The $variable$ variables only work with parameters from the macro -- you can't assign them inside the macro.

For variables that you create, you have to use the <<variable>> nomenclature, except inside a filter expression in which case you can use operator<variable> nomenclature.

Just to confuse things more, inside your macro you could also refer to the parameters like this

<<__title__>>  and <<__label__>>

This will get the default the way you want. I'm not sure why you're using the text widget instead of just placing the text, but anyways ...

\define mymac(title,label)

<$text text="""Title: $title$"""/>
<br>
<$text text="""Label: $label$"""/>
<br>

<$set name="label" filter="$label$" value="$label$" emptyValue="""$title$""">
<$text text="""Title: $title$"""/>
<br>
<$text text="""Label: """/>
<$text text=<<label>>/>

</$set>

\end

<<mymac title:"test" >>

Jon Dyer

unread,
Nov 2, 2020, 2:47:43 PM11/2/20
to TiddlyWiki
Thank you very much for the explanation! This was very helpful.
Reply all
Reply to author
Forward
0 new messages