2014-09-10 23:06:19 +00:00
caption: macrocall
2020-09-28 10:30:28 +00:00
created: 20131024141900000
modified: 20200928102843275
tags: Widgets
title: MacroCallWidget
type: text/vnd.tiddlywiki
2013-10-31 22:03:40 +00:00
! Introduction
2020-09-28 10:30:28 +00:00
The macro call widget provides a more flexible alternative syntax for invoking macros compared to the usual `<<macroname>>` syntax documented in [[Macros in WikiText]].
2013-10-31 22:03:40 +00:00
2020-09-28 10:30:28 +00:00
For example, a macro called `italicise` that takes a single parameter called `text` would usually be invoked like this:
2013-10-31 22:03:40 +00:00
```
<<italicise "Text to be made into italics">>
<<italicise text:"Text to be made into italics">>
2020-09-28 10:30:28 +00:00
```
The same macro can be invoked using the macro call widget like this:
```
2013-10-31 22:03:40 +00:00
<$macrocall $name="italicise" text="Text to be made into italics"/>
2013-11-01 15:00:43 +00:00
<$macrocall $name="italicise" text={{Title of tiddler containing text to be italicised}}/>
<$macrocall $name="italicise" text=<<textMaker "Another macro to generate the text to be italicised">>/>
2013-10-31 22:03:40 +00:00
```
2020-09-28 10:30:28 +00:00
The advantages of the widget formulation are:
* Macro parameters are specified as widget attributes, thus allowing indirection via `{{title!!field}}`, `<<macroname>>` or `{{{filter}}}`
* The output format can be chosen from several options:
** `text/html` wikifies the text of the macro
** `text/plain` wikifies the text of the macro and then extracts the plain text characters (ie. ignoring HTML tags)
** `text/raw` returns the plain text of the macro, without wikification
2013-11-01 15:00:43 +00:00
You can see several examples of the macro call widget within the core:
* Listing module information: [[$:/snippets/modules]]
* Listing field information: [[$:/snippets/allfields]]
* Generating `data:` URIs: [[$:/themes/tiddlywiki/starlight/styles.tid]]
2013-10-31 22:03:40 +00:00
! Content and Attributes
The content of the `<$macrocall>` widget is ignored.
|!Attribute |!Description |
|$name |Name of the macro to invoke |
2013-11-04 10:00:02 +00:00
|$type |ContentType with which the macro text should be parsed (defaults to `text/vnd.tiddlywiki`) |
2020-09-28 10:30:28 +00:00
|$output |ContentType for the output rendering (defaults to `text/html`, can also be `text/plain` or `text/raw`) |
2013-10-31 22:03:40 +00:00
|//parameters// |Macro parameters specified as attributes |