2023-07-31 11:13:37 +00:00
created: 20230726145210484
2024-07-28 12:40:58 +00:00
modified: 20240619211734149
2023-07-31 11:13:37 +00:00
tags: [[Variable Usage]]
title: Behaviour of invoked variables depends on how the variable was declared
type: text/vnd.tiddlywiki
\define m1(a1) $a1$ - <<__a1__>> - <<a1>>
\procedure p1(a1) $a1$ - <<__a1__>> - <<a1>>
\function f1(a1) "$a1$" "-" [<__a1__>] ="-" [<a1>] :and[join[ ]]
2024-07-28 12:40:58 +00:00
Invoked in normal wikitext context: `<$transclude $variable=myvar/>` or `<<myvar>>`
2023-07-31 11:13:37 +00:00
{{Behaviour of variables invoked via normal wikitext}}
2024-07-28 12:40:58 +00:00
Invoked via widget attribute: `<div class=<<myvar>>/>`
2023-07-31 11:13:37 +00:00
{{Behaviour of variables invoked via widget attributes}}
2024-07-28 12:40:58 +00:00
Invoked via filter operator parameter: `[<myvar>]`
2023-07-31 11:13:37 +00:00
{{Behaviour of variables invoked via filter operator parameter}}
2024-07-28 12:40:58 +00:00
Invoked via function call in a filter expression: `[function[.myfun]]`
2023-07-31 11:13:37 +00:00
{{Behaviour of variables invoked via filter expression function call}}
!! Examples
Below is an example macro, procedure and function definition. All three forms of parameter substitution `$a1$`, `<<__a1__>>`, and `<<a1>>` are included in each definition. The output helps illustrate when each form of substitution will or will not have affect.
```
\define m1(a1) $a1$ - <<__a1__>> - <<a1>>
\procedure p1(a1) $a1$ - <<__a1__>> - <<a1>>
\function f1(a1) $a1$ "-" [<__a1__>] ="-" [<a1>] :and[join[ ]]
```
| !Variable transclusion|!output |
| `<<m1 foo>>`|<<m1 foo>>|
| `<<p1 foo>>`|<<p1 foo>>|
| `<<f1 foo>>`|<<f1 foo>>|
| !Widget attribute|!output |
| `<$text text=<<m1 foo>>/>`|<$text text=<<m1 foo>>/>|
| `<$text text=<<p1 foo>>/>`|<$text text=<<p1 foo>>/>|
| `<$text text=<<f1 foo>>/>`|<$text text=<<f1 foo>>/>|
| !Filter operator parameter|!output |
| `[<m1 foo>]`|<$text text={{{[<m1 foo>]}}}/>|
| `[<p1 foo>]`|<$text text={{{[<p1 foo>]}}}/>|
| `[<f1 foo>]`|<$text text={{{[<f1 foo>]}}}/>|
| !Function call in filter expression|!output |
| `[function[m1],[foo]]`|<$text text={{{[function[m1],[foo]]}}}/>|
| `[function[p1],[foo]]`|<$text text={{{[function[p1],[foo]]}}}/>|
| `[function[f1],[foo]]`|<$text text={{{[function[f1],[foo]]}}}/>|