This is a stripped-down version of a single section of Grok TiddlyWiki, optimized for fast loading and readability by search engines. Some features are missing.

For the full Grok TiddlyWiki experience, please visit the wiki version of this page.

Ex:QuotedProcedureCall/answer

 7th October 2024 at 5:34pm

You get broken links – the URL just says <<article>> where the article name should be, when you hover over the link or click on it.

\procedure wikipediaLink(articleName, linkText:"Wikipedia Link")
  <a href=`https://en.wikipedia.org/wiki/$(articleName)$`>
  <<linkText>></a>
\end

<$let
  article="Aardvark"
  description="An animal"
>

* <$transclude $variable="wikipediaLink" articleName="<<article>>" linkText="<<description>>" />

</$let>

Putting quotation marks around a procedure call or variable reference passed to an HTML attribute makes it literal – that is, TiddlyWiki doesn't try to look at it to see if it's a variable or procedure call. This is very occasionally what you want, but usually it's a mistake.

The quotation marks should be omitted even if the procedure call has spaces in it. So for some made-up procedure myproc with two parameters, this would the correct way to call it, even though it may look wrong at first glance:

<$transclude $variable="wikipediaLink" linktext=<<myproc parameter1 "parameter 2">> articleName="Dingo"/>

But you might have noticed that while the link URL is incorrect, the text is correct. What's up with that?

We'll discuss this further in chapter 6, when we get to Wikification, but for now, notice that articleName is used as (part of) an attribute of an HTML element, while <<linkText>> is used directly in wikitext. This turns out to be the difference! When the value of an attribute, like href here, is evaluated, TiddlyWiki just takes the value of whatever is passed as the attribute – in this case it's the text <<article>> – and plops it into the URL string, and then it's done. In contrast, when the value of <<linkText>> is evaluated, TiddlyWiki similarly replaces it with <<description>>, but when TiddlyWiki parses wikitext (rather than attribute values), it keeps processing the result of each replacement over and over again, getting the values of any further references until there are no more. (We say it parses recursively, literally “running again.”) So on the second pass, it sees a variable <<description>> and replaces it with its value An animal, and everything is dandy.

In this case, the only bad effect of quoting <<description>> is that you make TiddlyWiki take very slightly longer to render the tiddler when you view it, since it has to do an extra step (and it's so fast at this you would never notice). But to avoid confusion, don't do that without a good reason – if you don't really mean that you want to display the literal text <<article>> within the procedure, don't write it that way.

Go to question: Ex:QuotedProcedureCall