mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-24 04:16:56 +00:00
Update macros docs
This commit is contained in:
parent
e1ac85ddd5
commit
9d53a1b5c4
@ -17,14 +17,39 @@ Hi, I'm $name$ and I live in $address$
|
||||
\end
|
||||
```
|
||||
|
||||
The first line of the definition specifies the macro name and any parameters. Parameters are named and can optionally have default values that are used if the parameter isn't specified at the time of calling. The body of the macro definition follows, terminated with `\end`. The macro can include parameters using the `$name$` construction.
|
||||
!! Parameter Substitution
|
||||
|
||||
The first line of the definition specifies the macro name and any parameters. Parameters are named and can optionally have default values that are used if the parameter isn't specified at the time of calling. The body of the macro definition follows, terminated with `\end` on a line by itself.
|
||||
|
||||
The text of the macro can reference parameters using the `$name$` syntax. The value of the parameter is substituted at the time the macro is invoked.
|
||||
|
||||
!! Variable Substitution
|
||||
|
||||
The values of named variables can also be substituted into the text of a macro using the syntax `$(variable)$`. For example:
|
||||
|
||||
```
|
||||
\define mysamplemacro2()
|
||||
Hi, I'm $(name)$ and I live in $(address)$
|
||||
\end
|
||||
\define name() Bugs Bunny
|
||||
|
||||
<$set name="address" value="Rabbit Hole Hill">
|
||||
<<mysamplemacro2>>
|
||||
</$set>
|
||||
```
|
||||
|
||||
The result is: `Hi, I'm Bugs Bunny and I live in Rabbit Hole Hill`.
|
||||
|
||||
!! Single Line macros
|
||||
|
||||
Single-line macros can omit the `\end` marker like this:
|
||||
|
||||
```
|
||||
\define mysamplemacro(name:"Bugs Bunny") Hi, I'm $name$
|
||||
\define mysamplemacro3(name:"Bugs Bunny") Hi, I'm $name$
|
||||
```
|
||||
|
||||
!! Macro Scope
|
||||
|
||||
Macro definitions must be placed at the top of a tiddler. Macros are available to the tiddler that defines them, plus any tiddlers that it transcludes.
|
||||
|
||||
Global macros can be defined in any tiddler with the tag [[$:/tags/Macro]]. They are then available within all tiddlers.
|
||||
@ -35,12 +60,13 @@ Macros can be imported from other tiddlers with the ImportVariablesWidget.
|
||||
|
||||
! Using Macros
|
||||
|
||||
Macros are used like this:
|
||||
In their simplest form, macros are used like this:
|
||||
|
||||
```
|
||||
<<mysamplemacro>>
|
||||
<<mysamplemacro "Donald Duck">>
|
||||
<<mysamplemacro "Mickey Mouse" "Mouse House">>
|
||||
<<mysamplemacro name:"Minnie Mouse" address:"Mouse House">>
|
||||
```
|
||||
|
||||
Resulting in:
|
||||
@ -49,10 +75,13 @@ Resulting in:
|
||||
Hi I'm Bugs Bunny and I live in Rabbit Hole Hill
|
||||
Hi I'm Donald Duck and I live in Rabbit Hole Hill
|
||||
Hi I'm Mickey Mouse and I live in Mouse House
|
||||
Hi I'm Minnie Mouse and I live in Mouse House
|
||||
|
||||
```
|
||||
|
||||
! Multiline Parameters
|
||||
Note that parameter values that do not specify names are mapped in sequence to the parameters defined in the macro.
|
||||
|
||||
!! Multiline Parameters
|
||||
|
||||
Parameters can include line breaks. For example:
|
||||
|
||||
@ -72,9 +101,9 @@ Rodentville,
|
||||
Ratland.""">>
|
||||
```
|
||||
|
||||
! Invoked
|
||||
! Using Macros with the MacroCallWidget
|
||||
|
||||
There are many different ways to invoke macro.A macro called `italicise` that takes a single parameter called `text` can be invoked in any of these ways:
|
||||
Macros can also be invoked with the MacroCallWidget
|
||||
|
||||
```
|
||||
<<italicise "Text to be made into italics">>
|
||||
@ -84,7 +113,7 @@ There are many different ways to invoke macro.A macro called `italicise` that ta
|
||||
<$macrocall $name="italicise" text=<<textMaker "Another macro to generate the text to be italicised">>/>
|
||||
```
|
||||
|
||||
''also see''
|
||||
Also see:
|
||||
|
||||
* [[Macros]]
|
||||
* [[MacroCallWidget]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user