2013-12-05 16:21:10 +00:00
created: 20131205160746466
2014-06-19 11:37:54 +00:00
modified: 20140619111725471
2013-12-05 16:21:10 +00:00
tags: wikitext
title: Macros in WikiText
type: text/vnd.tiddlywiki
2014-02-11 19:10:17 +00:00
! Defining Macros
2014-04-09 13:33:47 +00:00
Macros are snippets of text that can be inserted with a concise shortcut.
Multi-line macros are defined like this:
2013-12-05 16:21:10 +00:00
```
\define mysamplemacro(name:"Bugs Bunny",address:"Rabbit Hole Hill")
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.
2014-04-09 13:33:47 +00:00
Single-line macros can omit the `\end` marker like this:
```
\define mysamplemacro(name:"Bugs Bunny") Hi, I'm $name$
```
2013-12-05 16:21:10 +00:00
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.
2014-06-12 18:03:12 +00:00
Global macros can be defined in any tiddler with the tag [[$:/tags/Macro]]. They are then available within all tiddlers.
Macros can be imported from other tiddlers with the ImportVariablesWidget.
2014-02-11 19:10:17 +00:00
[[JavaScript Macros]] can also be used for more flexibility.
! Using Macros
2013-12-05 16:21:10 +00:00
Macros are used like this:
```
<<mysamplemacro>>
<<mysamplemacro "Donald Duck">>
<<mysamplemacro "Mickey Mouse" "Mouse House">>
```
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
```
2014-06-19 11:37:54 +00:00
! Multiline Parameters
Parameters can include line breaks. For example:
```
<<mysamplemacro "Mickey Mouse" "Mouse House,
Mouse Lane,
Rodentville,
Ratland.">>
```
By using triple-double quotes you can specify parameter values that include single double quotes. For example:
```
2014-06-24 13:37:11 +00:00
<<mysamplemacro "Mickey Mouse" """Mouse House,
2014-06-19 11:37:54 +00:00
"Mouse" Lane,
Rodentville,
Ratland.""">>
```