Another Newbie Question on Calling Macros

How did I even manage this one?

I’m trying to follow the GrokTiddlyWiki, but I’m finding a lot of problems following along. This one is one that would be helpful in a lot of different areas.

I’m slowly getting better at this. I think I spot two of your issues. First, you have one call mis-cased (calling getPhone instead of GetPhone.) Second, in the macrocall syntax you need to supply named arguments using : (colon) not = (equal). That is:

<<GetPhone person:{{!manager}}>>
<!--             ^-------- right here -->

Also that should be !! not just !:

<<GetPhone person:{{!!manager}}>>
<!--                 ^-------- right here -->

I’m not sure about the other one. It would help if you supplied text not just a screenshot, but I still don’t know if I’d get it… I’m getting better but still have a long way to go myself.

1 Like

@Scott_Sauyet is right on both points, but you’re also blending both ways to call a macro. The short form with the angle brackets can only take a literal parameter value:

<<GetPhone person:"John Smith">> <!-- okay -->
<<GetPhone "John Smith">> <!-- also okay; parameter names are unnecessary when each parameter is supplied in the same order as the macro definition. -->
<<GetPhone person:{{!!manager}}>> <!-- not okay-->
<<GetPhone {{!!manager}}>> <!-- not okay-->

To use more complicated parameter definitions (like defining a parameter based on a transclusion, or based on another variable) you’ll need the $macrocall widget:

<$macrocall $name="GetPhone" person={{!!manager}} />

Hope this helps!

1 Like

Interesting. Thank you @etardiff and @Scott_Sauyet. I see there is something wrong with the Grok Wiki then and I’ll have to be more careful. It is supposed to be going to a transclusion from a field so that I can change the imaginary girl’s imaginary manager and the it will fetch a different phone number. I can see several uses for this. Thank you for pointing out that I need both a full widget as well as the colons rather than the equals sign.

Ooops, not entirely fixed. When I have the equals the whole thing disappears, so there’s something wrong. When I have a colon it puts in Jane Doe’s number instead of the person in the Manager slot.

TW-Scripts is also a good place to learn some wikitext :wink:

From Screenshot I see several errors:

  • Your macro is GetPhone but your first call is <<getPhone not to the cases, TW is casesensitive

  • In second example you used $macrocall, where you allowed to pass variables to macro, so
    <$macrocall $name="GetPerson" person="manager" /> will work, manager here is a tiddler itself

  • You cannot pass macro attribute value using = so <<GetPhone person={{!!manager}} is wrong use instead <<GetPhone person:"manager">>

So it seems GrokTiddlyWiki is not wrong :wink:
I think you should read the docs carefully

Related question. I’ve a macro, purl and am trying to simplify to public, which needn’t take a variable:

\define purl(label)
[[public|https://applemcg.github.io/#$label$]]
\end

\define public()
[[public|https://applemcg.github.io/#{{!!title}}]]
\end

I’d like to replace <<purl "This Tiddler">> with <<public>>

I could be talked into another approach. Any that produces the link to the uploaded tiddler.

I figure i’m about two lesson’s too short of what it takes, having tried <<currentTiddler>>

I suspect I need to <$var something = " … something else …"> It’s no doubt buried in the wikitext syntax?

Within macros, $(variable)$ is substituted directly into the macro content (just like the $param$ syntax). This can be used to avoid passing macro parameters, by defining the variable outside the macro call. For example, suppose the current tiddler has a field named someField and you want to insert the value from that field into your link syntax. You could write:

\define someMacro() [[linklabel|https://example.com/#$(someVariable)$]]

<$let someVariable={{!!someField}}><<someMacro>></$let>

For your specific use-case – inserting the current tiddler’s title into the link – the TWCore already pre-defines the currentTiddler variable, which has the same value as the {{!!title}} field reference, so you don’t have to define the variable yourself, and you can just use it within your macro, like this:

\define public() [[public|https://applemcg.github.io/#$(currentTiddler)$]]

which you can then invoke using: <<public>>, without any parameter passing.

Also note how I used the single-line “short form” of macro definition, which eliminates the need for the \end syntax.

enjoy,
-e

1 Like

MNI Thanks, y muchas gracias !! que bueno