Query: How Do You Pass Parameters?

60 views
Skip to first unread message

TiddlyTweeter

unread,
Jun 25, 2020, 3:46:46 PM6/25/20
to TiddlyWiki
I try to be brief ...

\define thing(thingie:"wotnot")

 User enters ...

<<thing "hammer">>

 I have a second macro ...

\define dostuff(thingie:"wotnot")

How do I get "dostuff" to know the parameter value is now "hammer", not "wotnot"?

This is probably awfully unclear!

Trying to grasp basics.
TT

Mark S.

unread,
Jun 25, 2020, 4:04:01 PM6/25/20
to TiddlyWiki
What you're not showing, which I think must be the missing step, is how you call "dostuff". If you call it like

<<dostuff "hammer">>

it should use "hammer", just like "thing" did. So not sure what the problem is, unless you're calling dostuff in relation to "thing", somehow.

TiddlyTweeter

unread,
Jun 25, 2020, 4:16:49 PM6/25/20
to TiddlyWiki
I *think* I get it. I'll try & see.

TT

TW Tones

unread,
Jun 25, 2020, 7:54:54 PM6/25/20
to tiddl...@googlegroups.com
TT,

This would be worth a simple summary, to guide users. Since I am not so sure about your question, I suspect you just had a "mind block".

[Edit Minor typos]

In your case 
<<dostuff "hammer">> will change $thingie$ to be "hammer"

The following is a little verbose because it forms part of a future blog post

Basically 
  • if you want to use parameters in a macro they need to be named in the braces macroname(p1 p3) the access them with $p1$ $p2$
  • You can set a default value for parameters with (p1:"defaultvalue",p2)
  • When calling the macro the `<<macroname>>` is a little limited, only literal strings can be used ` <<macroname "value1" "Value2">>`
    • Here we are relying on the order of the parameters
  • If you want to pass parameters out of order you need to name them, for example we may want to use the default for p1 and pass only value2
    • We use `<<macroname p2:"value2">>` uses the same format as inside the definition braces ().
  • The only way to pass variables and field values to a macro is the macrocall widget
    • `<$macrocall $name="macroname" p1={{!!fieldname)) p2=<<variable>> p3=<<wikifiedmacro>>/>`
  • However variables in the calling wikitext can be accessed in macros with $(varname)$ without being added to the parameters
  • Whenever something is wrapped in $ signs the value is replaced before the wikitext/macro is evaluated., ro $values$ or $(varname)$ may need to be quotes etc..
    • `<$tiddler tiddler="[[($currentTiddler$)]]">...` (only in macro definitions)
  • There may be cases where you want to use one of the parameters as if it were a variable 
    • `<$tiddler tiddler=<<__p2__>> >...`
Other ways to set default value for parameters
\define macroname(p1 p2)
<$set name=p1 value="$p1$"emptyValue="defaultValue">

Use <<p1>> not $p1$

</$set>
\end

See how this converts the parameter to a variable?
The default value can be other references or macros as well.

You can even set the `p1` variable multiple times
<$set name=p1 value="$p1$"emptyValue="$(varname)$">
<$set name=p1 value=<
<p1>>"emptyValue="defaultValue">

Use <
<p1>> not $p1$

</$set>
</$set>
In this case if no parameter is provided, and the first emptyValue="$(varname)$" is itself empty
Then the defaultvalue will be set

Regards
TW Tones


Reply all
Reply to author
Forward
0 new messages