Best Practice: Displaying Message Inside Macro

Assume you have a macro with few input parameters, and you want to display a message (passed as parameter) inside macro. What is the best practice to do this?

Example

\define myMacro(a, b, msg)
some wikitext script
...
..
You need to display the message here: $msg$
...
some more wikitext script
\end

You have different options

  1. use text substitution $msg$
  2. wikifying uaing <<__msg__>>
  3. using text widget <$text text=<<__msg__>> />
  4. using transclude widget <$transclude tiddler=<<__msg__>> field=title />
  5. …

How do you display the message inside macro, passes as input parameter?

No. 1 … text substitution … should be avoided.
No. 2 … can be avoided for 99% of usecases … It’s very performance intensive if used in the wrong way.

No. 3 … OK if you do not need wikitext formatting.

  • It’s the best way to use inside a link widget, to avoid “double linking”
    eg: <$link to="HelloThere"> ThisLinks to HelloThere</$link>
    … If you hover ThisLinks with the mouse you’ll see what’s going on
  • best practice: <$link to="HelloThere"><$text text="ThisLinks to HelloThere"/></$link>

No 4 … Will be even better once “parameterized transclusions” are available


IMO the most flexible way to use text substitution in TW atm is like this.

<$let dynamicText={{{ "plain text" [<text-from-a-variable>] [{text-from-a-tiddler}] [{text-from-a-tiddler!!field}] "some more plain text" +[join[/]] }}} >
4 Likes